diff options
Diffstat (limited to 'plugins/CustomDimensions/angularjs')
13 files changed, 672 insertions, 0 deletions
diff --git a/plugins/CustomDimensions b/plugins/CustomDimensions deleted file mode 160000 -Subproject 318661a2fb1ef3b3e5d6d999ae8b9628cb5a113 diff --git a/plugins/CustomDimensions/angularjs/manage/edit.controller.js b/plugins/CustomDimensions/angularjs/manage/edit.controller.js new file mode 100644 index 0000000000..39993b6545 --- /dev/null +++ b/plugins/CustomDimensions/angularjs/manage/edit.controller.js @@ -0,0 +1,141 @@ +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +(function () { + angular.module('piwikApp').controller('CustomDimensionsEditController', CustomDimensionsEditController); + + CustomDimensionsEditController.$inject = ['$scope', 'customDimensionsModel', 'piwik', '$location', '$filter']; + + function CustomDimensionsEditController($scope, customDimensionsModel, piwik, $location, $filter) { + + var self = this; + var currentId = null; + var notificationId = 'customdimensions'; + + var translate = $filter('translate'); + + this.model = customDimensionsModel; + + function getNotification() + { + var UI = require('piwik/UI'); + return new UI.Notification(); + } + + function removeAnyCustomDimensionNotification() + { + getNotification().remove(notificationId); + } + + function showNotification(message, context) + { + var notification = getNotification(); + notification.show(message, {context: context, id: notificationId}); + } + + function init(dimensionId) + { + self.create = dimensionId == '0'; + self.edit = !(dimensionId == '0'); + + if (dimensionId !== null) { + removeAnyCustomDimensionNotification(); + } + + self.model.fetchCustomDimensionsConfiguration().then(function () { + + if (self.edit && dimensionId) { + self.model.findCustomDimension(dimensionId).then(function (dimension) { + self.dimension = dimension; + if (dimension && !dimension.extractions.length) { + self.addExtraction(); + } + }); + } else if (self.create) { + self.dimension = { + idSite: piwik.idSite, + name: '', + active: false, + extractions: [], + scope: $scope.dimensionScope, + case_sensitive: true, + }; + self.addExtraction(); + } + }); + } + + this.removeExtraction = function(index) + { + if (index > -1) { + this.dimension.extractions.splice(index, 1); + } + }; + + this.addExtraction = function() + { + if (this.doesScopeSupportExtraction()) { + this.dimension.extractions.push({dimension: 'url', pattern: ''}); + } + }; + + this.doesScopeSupportExtraction = function () { + if (!this.dimension || !this.dimension.scope || !this.model.availableScopes) { + return false; + } + + var index, scope; + for (index in this.model.availableScopes) { + scope = this.model.availableScopes[index]; + if (scope && scope.value === this.dimension.scope) { + return scope.supportsExtractions; + } + } + + return false; + }; + + this.createCustomDimension = function () { + var method = 'CustomDimensions.configureNewCustomDimension'; + + this.isUpdating = true; + + customDimensionsModel.createOrUpdateDimension(this.dimension, method).then(function (response) { + if (response.type === 'error') { + return; + } + + showNotification(translate('CustomDimensions_DimensionCreated'), response.type); + self.model.reload(); + $location.url('/list'); + }); + }; + + this.updateCustomDimension = function () { + this.dimension.idDimension = this.dimension.idcustomdimension; + + var method = 'CustomDimensions.configureExistingCustomDimension'; + + this.isUpdating = true; + + customDimensionsModel.createOrUpdateDimension(this.dimension, method).then(function (response) { + if (response.type === 'error') { + return; + } + + showNotification(translate('CustomDimensions_DimensionUpdated'), response.type); + $location.url('/list'); + }); + }; + + $scope.$watch('dimensionId', function (newValue, oldValue) { + if (newValue != oldValue || currentId === null) { + currentId = newValue; + init(newValue); + } + }); + } +})();
\ No newline at end of file diff --git a/plugins/CustomDimensions/angularjs/manage/edit.directive.html b/plugins/CustomDimensions/angularjs/manage/edit.directive.html new file mode 100644 index 0000000000..aeb26b60ff --- /dev/null +++ b/plugins/CustomDimensions/angularjs/manage/edit.directive.html @@ -0,0 +1,102 @@ +<div class="editCustomDimension"> + <div piwik-content-block content-title="{{ 'CustomDimensions_ConfigureDimension'|translate:(dimensionScope|ucfirst):(editDimension.dimension.index || '') }}"> + + <p ng-show="editDimension.model.isLoading || editDimension.model.isUpdating"> + <span class="loadingPiwik"><img src="plugins/Morpheus/images/loading-blue.gif"/> {{ 'General_LoadingData'|translate }}</span> + </p> + + <div ng-show="!editDimension.model.isLoading"> + <form ng-submit="editDimension.edit ? editDimension.updateCustomDimension() : editDimension.createCustomDimension()"> + + <div piwik-field uicontrol="text" name="name" + ng-model="editDimension.dimension.name" + title="{{ 'General_Name'|translate }}" + maxlength="255" + required="true" + inline-help="{{ 'CustomDimensions_NameAllowedCharacters'|translate }}"> + </div> + + <div piwik-field uicontrol="checkbox" name="active" + ng-model="editDimension.dimension.active" + title="{{ 'CorePluginsAdmin_Active'|translate }}" + inline-help="{{ 'CustomDimensions_CannotBeDeleted'|translate }}"> + </div> + + <div class="row form-group" ng-show="editDimension.doesScopeSupportExtraction()"> + + <h3 class="col s12">{{ 'CustomDimensions_ExtractValue'|translate }}</h3> + + <div class="col s12 m6"> + + <div ng-repeat="(index, extraction) in editDimension.dimension.extractions" class="extraction {{ index }}"> + + <div class="row"> + + <div class="col s12 m6"> + <div piwik-field uicontrol="select" name="dimension{{index}}" + ng-model="editDimension.dimension.extractions[index].dimension" + full-width="true" + options="editDimension.model.extractionDimensions"> + </div></div> + <div class="col s12 m6"> + <div piwik-field uicontrol="text" name="pattern{{index}}" + full-width="true" + ng-model="editDimension.dimension.extractions[index].pattern" + title="{{ editDimension.dimension.extractions[index].dimension === 'urlparam' ? 'url query string parameter' : 'eg. /blog/(.*)/' }}" + > + </div> + </div> + <div class="col s12"> + <span ng-click="editDimension.addExtraction()" + ng-show="editDimension.dimension.extractions[index].pattern" + class="icon-plus"></span> + <span ng-click="editDimension.removeExtraction(index)" + ng-show="(editDimension.dimension.extractions|length) > 1" + class="icon-minus"></span> + </div> + </div> + + </div> + + <div class="row"> + <div class="col s12"> + <div piwik-field uicontrol="checkbox" name="casesensitive" + ng-show="editDimension.dimension.extractions[0].pattern" + ng-model="editDimension.dimension.case_sensitive" + title="{{ 'Goals_CaseSensitive'|translate }}"> + </div> + </div> + </div> + + </div> + <div class="col s12 m6 form-help"> + {{ 'CustomDimensions_ExtractionsHelp'|translate }} + </div> + </div> + + <input class="btn update" type="submit" ng-show="editDimension.edit" ng-disabled="editDimension.model.isUpdating" value="Update"> + <input class="btn create" type="submit" ng-show="editDimension.create" ng-disabled="editDimension.model.isUpdating" value="Create"> + <a class="btn cancel" type="button" ng-href="#list">{{ 'General_Cancel'|translate }}</a> + </form> + + <div class="alert alert-info howToTrackInfo" ng-show="editDimension.edit"> + <strong>{{ 'CustomDimensions_HowToTrackManuallyTitle'|translate }}</strong> + <p> + {{ 'CustomDimensions_HowToTrackManuallyViaJs'|translate }} + </p> + <pre piwik-select-on-focus><code>_paq.push(['setCustomDimension', {{ editDimension.dimension.idcustomdimension }}, '{{ 'CustomDimensions_ExampleValue'|translate }}']);</code></pre> + <p ng-bind-html="'CustomDimensions_HowToTrackManuallyViaJsDetails'|translate:'<a target=_blank href=\'https://developer.piwik.org/guides/tracking-javascript-guide#custom-dimensions\'>':'</a>'"> + </p> + <p> + {{ 'CustomDimensions_HowToTrackManuallyViaPhp'|translate }} + </p> + <pre piwik-select-on-focus><code>$tracker->setCustomTrackingParameter('dimension{{ editDimension.dimension.idcustomdimension }}', '{{ 'CustomDimensions_ExampleValue'|translate }}');</code></pre> + <p> + {{ 'CustomDimensions_HowToTrackManuallyViaHttp'|translate }} + </p> + <pre piwik-select-on-focus><code>&dimension{{ editDimension.dimension.idcustomdimension }}={{ 'CustomDimensions_ExampleValue'|translate }}</code></pre> + </div> + </div> + + </div> +</div>
\ No newline at end of file diff --git a/plugins/CustomDimensions/angularjs/manage/edit.directive.js b/plugins/CustomDimensions/angularjs/manage/edit.directive.js new file mode 100644 index 0000000000..ceafc6fb75 --- /dev/null +++ b/plugins/CustomDimensions/angularjs/manage/edit.directive.js @@ -0,0 +1,30 @@ +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +/** + * Usage: + * <div piwik-custom-dimensions-edit> + */ +(function () { + angular.module('piwikApp').directive('piwikCustomDimensionsEdit', piwikCustomDimensionsEdit); + + piwikCustomDimensionsEdit.$inject = ['piwik']; + + function piwikCustomDimensionsEdit(piwik){ + + return { + restrict: 'A', + scope: { + dimensionId: '=', + dimensionScope: '=', + }, + templateUrl: 'plugins/CustomDimensions/angularjs/manage/edit.directive.html?cb=' + piwik.cacheBuster, + controller: 'CustomDimensionsEditController', + controllerAs: 'editDimension' + }; + } +})();
\ No newline at end of file diff --git a/plugins/CustomDimensions/angularjs/manage/edit.directive.less b/plugins/CustomDimensions/angularjs/manage/edit.directive.less new file mode 100644 index 0000000000..515681d4ac --- /dev/null +++ b/plugins/CustomDimensions/angularjs/manage/edit.directive.less @@ -0,0 +1,25 @@ +.editCustomDimension { + .icon-plus, .icon-minus { + cursor: pointer; + font-size: 16px; + padding-left: 10px; + } + + .extraction { + .form-group { + margin-top: 8px; + margin-bottom: 8px; + } + } + + .howToTrackInfo { + margin-top: 32px; + strong { + margin-bottom: 16px; + display: inline-block; + } + pre { + margin-top: 0; + } + } +}
\ No newline at end of file diff --git a/plugins/CustomDimensions/angularjs/manage/list.controller.js b/plugins/CustomDimensions/angularjs/manage/list.controller.js new file mode 100644 index 0000000000..c4ca6a9e78 --- /dev/null +++ b/plugins/CustomDimensions/angularjs/manage/list.controller.js @@ -0,0 +1,19 @@ +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +(function () { + angular.module('piwikApp').controller('CustomDimensionsListController', CustomDimensionsListController); + + CustomDimensionsListController.$inject = ['customDimensionsModel', 'piwik']; + + function CustomDimensionsListController(customDimensionsModel, piwik) { + customDimensionsModel.fetchCustomDimensionsConfiguration(); + + this.siteName = piwik.siteName; + + this.model = customDimensionsModel; + } +})();
\ No newline at end of file diff --git a/plugins/CustomDimensions/angularjs/manage/list.directive.html b/plugins/CustomDimensions/angularjs/manage/list.directive.html new file mode 100644 index 0000000000..d1f5ab2f5d --- /dev/null +++ b/plugins/CustomDimensions/angularjs/manage/list.directive.html @@ -0,0 +1,55 @@ +<div> + <div piwik-content-intro> + <h2 piwik-enriched-headline>{{ 'CustomDimensions_CustomDimensions'|translate }}</h2> + + <p ng-bind-html="('CustomDimensions_CustomDimensionsIntro'|translate:'<a target=_blank href=\'https://piwik.org/docs/custom-dimensions\'>':'</a>':dimensionsList.siteName) + ' ' + ('CustomDimensions_CustomDimensionsIntroNext'|translate:'<a target=_blank href=\'https://piwik.org/docs/custom-variables\'>':'</a>':'<a target=_blank href=\'https://piwik.org/faq/general/faq_21117\'>':'</a>') "> + </p> + + <p ng-show="dimensionsList.model.isLoading"> + <span class="loadingPiwik"><img src="plugins/Morpheus/images/loading-blue.gif"/> {{ 'General_LoadingData'|translate }}</span> + </p> + </div> + + <div ng-repeat="scope in dimensionsList.model.availableScopes" ng-show="!dimensionsList.model.isLoading"> + <div piwik-content-block content-title="{{ scope.name }} Dimensions"> + + <p> + {{ 'CustomDimensions_ScopeDescription' + (scope.value|ucfirst) |translate }} + {{ 'CustomDimensions_ScopeDescription' + (scope.value|ucfirst) + 'MoreInfo' |translate }} + </p> + + <table piwik-content-table> + <thead> + <tr> + <th class="index">{{ 'General_Id'|translate }}</th> + <th class="name">{{ 'General_Name'|translate }}</th> + <th class="extractions" ng-show="scope.supportsExtractions">{{ 'CustomDimensions_Extractions'|translate }}</th> + <th class="active">{{ 'CorePluginsAdmin_Active'|translate }}</th> + <th class="action">{{ 'General_Action'|translate }}</th> + </tr> + </thead> + <tbody> + <tr ng-show="scope.numSlotsUsed == 0 && !dimensionsList.model.isLoading"> + <td colspan="5">{{ 'CustomDimensions_NoCustomDimensionConfigured'|translate }}</td> + </tr> + <tr ng-repeat="customDimension in dimensionsList.model.customDimensions|filter:{scope: scope.value}|orderBy:'idcustomdimension'" + class="customdimension" ng-class="customDimension.idcustomdimension"> + <td class="index">{{ customDimension.idcustomdimension }}</td> + <td class="name">{{ customDimension.name }}</td> + <td class="extractions" ng-show="scope.supportsExtractions"><span ng-class="{'icon-ok': customDimension.extractions[0].pattern}"></span></td> + <td class="active"><span ng-class="{'icon-ok': customDimension.active}"></span></td> + <td class="action"><a ng-href="#?idDimension={{ customDimension.idcustomdimension }}&scope={{ scope.value }}" class="table-action icon-edit" ng-click="addCustomVar"></a></td> + </tr> + </tbody> + </table> + + <div class="tableActionBar"> + <a class="{{scope.value }}" ng-show="!dimensionsList.model.isLoading" + value="" ng-href="#?idDimension=0&scope={{ scope.value }}" ng-class="{'disabled': !scope.numSlotsLeft}" + ><span class="icon-add"></span> {{ 'CustomDimensions_ConfigureNewDimension'|translate }} + <span class="info">({{ 'CustomDimensions_XofYLeft'|translate:scope.numSlotsLeft:scope.numSlotsAvailable }})</span></a> + </div> + + </div> + </div> +</div> diff --git a/plugins/CustomDimensions/angularjs/manage/list.directive.js b/plugins/CustomDimensions/angularjs/manage/list.directive.js new file mode 100644 index 0000000000..c01eb0330e --- /dev/null +++ b/plugins/CustomDimensions/angularjs/manage/list.directive.js @@ -0,0 +1,27 @@ +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +/** + * Usage: + * <div piwik-custom-dimensions-list> + */ +(function () { + angular.module('piwikApp').directive('piwikCustomDimensionsList', piwikCustomDimensionsList); + + piwikCustomDimensionsList.$inject = ['piwik']; + + function piwikCustomDimensionsList(piwik){ + + return { + restrict: 'A', + scope: {}, + templateUrl: 'plugins/CustomDimensions/angularjs/manage/list.directive.html?cb=' + piwik.cacheBuster, + controller: 'CustomDimensionsListController', + controllerAs: 'dimensionsList' + }; + } +})();
\ No newline at end of file diff --git a/plugins/CustomDimensions/angularjs/manage/list.directive.less b/plugins/CustomDimensions/angularjs/manage/list.directive.less new file mode 100644 index 0000000000..3dddd502a8 --- /dev/null +++ b/plugins/CustomDimensions/angularjs/manage/list.directive.less @@ -0,0 +1,24 @@ +.manageCustomDimensions { + + .dataTable { + max-width: 1000px; + } + + p, pre { + max-width: 1000px; + } + + th.action, td.action { + a { + color: black; + } + } + + .index { + width: 100px; + } + + .extractions, .active, th.action, td.action { + width: 150px; + } +} diff --git a/plugins/CustomDimensions/angularjs/manage/manage.controller.js b/plugins/CustomDimensions/angularjs/manage/manage.controller.js new file mode 100644 index 0000000000..58ec4772d7 --- /dev/null +++ b/plugins/CustomDimensions/angularjs/manage/manage.controller.js @@ -0,0 +1,68 @@ +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +(function () { + angular.module('piwikApp').controller('ManageCustomDimensionsController', ManageCustomDimensionsController); + + ManageCustomDimensionsController.$inject = ['$scope', '$rootScope', '$location', 'piwik']; + + function ManageCustomDimensionsController($scope, $rootScope, $location, piwik) { + + this.editMode = false; + + var self = this; + + function getValidDimensionScope(scope) + { + if (-1 !== ['action', 'visit'].indexOf(scope)) { + return scope; + } + + return ''; + } + + function initState() { + // as we're not using angular router we have to handle it manually here + var $search = $location.search(); + if ('idDimension' in $search) { + + var scope = getValidDimensionScope($search['scope']); + + if ($search.idDimension === 0 || $search.idDimension === '0') { + var parameters = {isAllowed: true, scope: scope}; + $rootScope.$emit('CustomDimensions.initAddDimension', parameters); + if (parameters && !parameters.isAllowed) { + self.editMode = false; + self.dimensionId = null; + self.dimensionScope = ''; + + return; + } + } + + self.editMode = true; + self.dimensionId = parseInt($search['idDimension'], 10); + self.dimensionScope = scope; + } else { + self.editMode = false; + self.dimensionId = null; + self.dimensionScope = ''; + } + + piwik.helper.lazyScrollToContent(); + } + + initState(); + + var onChangeSuccess = $rootScope.$on('$locationChangeSuccess', initState); + + $scope.$on('$destroy', function() { + if (onChangeSuccess) { + onChangeSuccess(); + } + }); + } +})(); diff --git a/plugins/CustomDimensions/angularjs/manage/manage.directive.html b/plugins/CustomDimensions/angularjs/manage/manage.directive.html new file mode 100644 index 0000000000..db1727e592 --- /dev/null +++ b/plugins/CustomDimensions/angularjs/manage/manage.directive.html @@ -0,0 +1,30 @@ +<div class="manageCustomDimensions"> + + <div ng-show="!manageDimensions.editMode"> + <div piwik-custom-dimensions-list></div> + + <div piwik-content-block content-title="{{ 'CustomDimensions_IncreaseAvailableCustomDimensionsTitle'|translate }}" id="customDimensionsCreateMoreDimensions"> + + <p> + {{ 'CustomDimensions_IncreaseAvailableCustomDimensionsTakesLong'|translate }} + <br><br>{{ 'CustomDimensions_HowToCreateCustomDimension'|translate }} + <br><br> + </p> + <pre piwik-select-on-focus><code>./console customdimensions:add-custom-dimension --scope=action +./console customdimensions:add-custom-dimension --scope=visit</code></pre> + <p> + {{ 'CustomDimensions_HowToManyCreateCustomDimensions'|translate }} + + {{ 'CustomDimensions_ExampleCreateCustomDimensions'|translate:5 }} + </p> + <pre piwik-select-on-focus><code>./console customdimensions:add-custom-dimension --scope=action --count=5</code></pre> + + </div> + + </div> + <div ng-show="manageDimensions.editMode"> + <div piwik-custom-dimensions-edit + dimension-id="manageDimensions.dimensionId" + dimension-scope="manageDimensions.dimensionScope"></div> + </div> +</div> diff --git a/plugins/CustomDimensions/angularjs/manage/manage.directive.js b/plugins/CustomDimensions/angularjs/manage/manage.directive.js new file mode 100644 index 0000000000..d9c937cb1c --- /dev/null +++ b/plugins/CustomDimensions/angularjs/manage/manage.directive.js @@ -0,0 +1,27 @@ +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +/** + * Usage: + * <div piwik-custom-dimensions-manage> + */ +(function () { + angular.module('piwikApp').directive('piwikCustomDimensionsManage', piwikManageCustomDimensions); + + piwikManageCustomDimensions.$inject = ['piwik']; + + function piwikManageCustomDimensions(piwik){ + + return { + restrict: 'A', + scope: {}, + templateUrl: 'plugins/CustomDimensions/angularjs/manage/manage.directive.html?cb=' + piwik.cacheBuster, + controller: 'ManageCustomDimensionsController', + controllerAs: 'manageDimensions' + }; + } +})();
\ No newline at end of file diff --git a/plugins/CustomDimensions/angularjs/manage/model.js b/plugins/CustomDimensions/angularjs/manage/model.js new file mode 100644 index 0000000000..f2318e1dfc --- /dev/null +++ b/plugins/CustomDimensions/angularjs/manage/model.js @@ -0,0 +1,124 @@ +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +(function () { + angular.module('piwikApp').factory('customDimensionsModel', customDimensionsModel); + + customDimensionsModel.$inject = ['piwikApi', '$q']; + + function customDimensionsModel(piwikApi, $q) { + var fetchAllPromise; + + var model = { + customDimensions : [], + availableScopes: [], + extractionDimensions: [], + isLoading: false, + isUpdating: false, + fetchCustomDimensionsConfiguration: fetchCustomDimensionsConfiguration, + findCustomDimension: findCustomDimension, + createOrUpdateDimension: createOrUpdateDimension, + reload: reload + }; + + return model; + + function reload() + { + model.customDimensions = []; + model.availableScopes = []; + model.extractionDimensions = []; + fetchAllPromise = null; + fetchCustomDimensionsConfiguration(); + } + + function fetchCustomDimensionsConfiguration() { + if (fetchAllPromise) { + return fetchAllPromise; + } + + model.isLoading = true; + + var deferred = $q.defer(); + // .fetch does not return a proper promise + piwikApi.fetch({method: 'CustomDimensions.getConfiguredCustomDimensions', filter_limit: '-1'}).then(function (customDimensions) { + model.customDimensions = customDimensions; + deferred.resolve(customDimensions); + }); + + fetchAllPromise = $q.all([deferred.promise, fetchAvailableScopes(), fetchAvailableExtractionDimensions()]).then(function () { + model.isLoading = false; + + return model.customDimensions; + }); + + return fetchAllPromise; + } + + function fetchAvailableExtractionDimensions() { + var deferred = $q.defer(); + // .fetch does not return a proper promise + piwikApi.fetch({method: 'CustomDimensions.getAvailableExtractionDimensions', filter_limit: '-1'}).then(function (availableExtractionDimensions) { + + model.extractionDimensions = []; + angular.forEach(availableExtractionDimensions, function (value) { + model.extractionDimensions.push({key: value.value, value: value.name}); + }); + deferred.resolve(availableExtractionDimensions); + }); + + return deferred.promise; + } + + function fetchAvailableScopes() { + var deferred = $q.defer(); + + // .fetch does not return a proper promise + piwikApi.fetch({method: 'CustomDimensions.getAvailableScopes', filter_limit: '-1'}).then(function (availableScopes) { + model.availableScopes = availableScopes; + deferred.resolve(availableScopes); + }); + + return deferred.promise; + } + + function findCustomDimension(customDimensionId) { + return fetchCustomDimensionsConfiguration().then(function (customDimensions) { + var found; + angular.forEach(customDimensions, function (dimension) { + if (parseInt(dimension.idcustomdimension, 10) === customDimensionId) { + found = dimension; + } + }); + + return found; + }); + } + + function createOrUpdateDimension(dimension, method) { + dimension = angular.copy(dimension); + dimension.active = dimension.active ? '1' : '0'; + dimension.method = method; + var extractions = dimension.extractions; + delete dimension.extractions; + + dimension.caseSensitive = dimension.case_sensitive ? '1' : '0'; + delete dimension.case_sensitive; + + model.isUpdating = true; + + return piwikApi.post(dimension, {extractions: extractions}).then(function (response) { + model.isUpdating = false; + + return {type: 'success'}; + + }, function (error) { + model.isUpdating = false; + return {type: 'error', message: error}; + }); + } + } +})();
\ No newline at end of file |