Skip to content

Instantly share code, notes, and snippets.

@diosmosis
Last active November 7, 2019 23:58
Show Gist options
  • Save diosmosis/cc2b1a67f1d1c6c6747761be104d6999 to your computer and use it in GitHub Desktop.
Save diosmosis/cc2b1a67f1d1c6c6747761be104d6999 to your computer and use it in GitHub Desktop.
import scheduler controller 2
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
(function () {
angular.module('piwikApp').controller('ImportSchedulerController', ImportSchedulerController);
ImportSchedulerController.$inject = [
'piwikApi',
'piwikPeriods',
'piwik'
];
function ImportSchedulerController(piwikApi, piwikPeriods, piwik) {
var vm = this;
vm.nonce = null;
vm.isStartingImport = false;
vm.startImport = startImport;
function startImport() {
if (vm.startDate) {
try {
piwikPeriods.parseDate(vm.startDate);
} catch (e) {
var UI = require('piwik/UI');
var notification = new UI.Notification();
notification.show(_pk_translate('GoogleAnalyticsImporter_InvalidDateFormat', 'YYYY-MM-DD'), {context: 'error'});
return;
}
}
vm.isStartingImport = true;
piwikApi.withTokenInUrl();
return piwikApi.post({
module: 'GoogleAnalyticsImporter',
action: 'startImport',
startDate: vm.startDate,
endDate: vm.endDate,
propertyId: vm.propertyId,
viewId: vm.viewId,
nonce: vm.nonce,
accountId: vm.accountId,
format: 'html',
}, { token_auth: piwik.token_auth }).then(function (r) {
console.log('succeeded');
console.log(r);
$('body').append(r);
}).catch(function (r) {
console.log('failed');
console.log(r);
})['finally'](function () {
//window.location.reload();
});
}
return vm;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment