diff --git a/.gitignore b/.gitignore index c8c9480..71f2693 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,6 @@ -tests/System/processed/*xml \ No newline at end of file +tests/System/processed/*xml +tests/System/processed/*text +/vue/dist/demo.html +/vue/dist/*.common.js +/vue/dist/*.map +/vue/dist/*.development.* diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..7275d80 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# CHANGELOG + +* 4.1.0 migrate from AngularJS to Vue. diff --git a/CustomVariables.php b/CustomVariables.php index fcf1c10..6debed8 100644 --- a/CustomVariables.php +++ b/CustomVariables.php @@ -20,7 +20,6 @@ class CustomVariables extends \Piwik\Plugin public function registerEvents() { return array( - 'AssetManager.getJavaScriptFiles' => 'getJsFiles', 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', 'Dimension.addDimensions' => 'addDimensions', @@ -137,14 +136,7 @@ public function getClientSideTranslationKeys(&$translationKeys) public function getStylesheetFiles(&$stylesheets) { - $stylesheets[] = "plugins/CustomVariables/angularjs/manage-custom-vars/manage-custom-vars.directive.less"; - } - - public function getJsFiles(&$jsFiles) - { - $jsFiles[] = "plugins/CustomVariables/angularjs/manage-custom-vars/manage-custom-vars.model.js"; - $jsFiles[] = "plugins/CustomVariables/angularjs/manage-custom-vars/manage-custom-vars.controller.js"; - $jsFiles[] = "plugins/CustomVariables/angularjs/manage-custom-vars/manage-custom-vars.directive.js"; + $stylesheets[] = "plugins/CustomVariables/vue/src/ManageCustomVars/ManageCustomVars.less"; } public function provideActionDimensionFields(&$fields, &$joins) diff --git a/angularjs/manage-custom-vars/manage-custom-vars.controller.js b/angularjs/manage-custom-vars/manage-custom-vars.controller.js deleted file mode 100644 index b6c9983..0000000 --- a/angularjs/manage-custom-vars/manage-custom-vars.controller.js +++ /dev/null @@ -1,22 +0,0 @@ -/*! - * 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('ManageCustomVarsController', ManageCustomVarsController); - - ManageCustomVarsController.$inject = ['manageCustomVarsModel', 'piwik', '$filter']; - - function ManageCustomVarsController(manageCustomVarsModel, piwik, $filter) { - manageCustomVarsModel.fetchUsages(); - - this.model = manageCustomVarsModel; - this.siteName = piwik.siteName; - this.scopes = [ - {value: 'visit', name: _pk_translate('General_TrackingScopeVisit')}, - {value: 'page', name: _pk_translate('General_TrackingScopePage')} - ]; - } -})(); \ No newline at end of file diff --git a/angularjs/manage-custom-vars/manage-custom-vars.directive.html b/angularjs/manage-custom-vars/manage-custom-vars.directive.html deleted file mode 100644 index aaeb4ad..0000000 --- a/angularjs/manage-custom-vars/manage-custom-vars.directive.html +++ /dev/null @@ -1,63 +0,0 @@ -
-
-

- {{ 'CustomVariables_CustomVariables'|translate }} -

- -

- -

-
- -
- {{ 'CustomVariables_SlotsReportIsGeneratedOverTime'|translate }} -
- -
-
- - - - - - - - - - - - - - - - -
{{'CustomVariables_Index'|translate }}{{'CustomVariables_Usages'|translate }}
{{ 'General_Loading'|translate }}
{{ customVariables.index }} - {{'CustomVariables_Unused'|translate }} - - {{ cvar.name }}, - -
-
-
- -
- -

- {{ 'CustomVariables_CreatingCustomVariableTakesTime'|translate }} -

- -
-
- {{ 'CustomVariables_ToCreateCustomVarExecute'|translate }} -
-

./console customvariables:set-max-custom-variables {{ manageCustomVars.model.numSlotsAvailable + 1 }}
-

- -
- -
diff --git a/angularjs/manage-custom-vars/manage-custom-vars.directive.js b/angularjs/manage-custom-vars/manage-custom-vars.directive.js deleted file mode 100644 index adbf957..0000000 --- a/angularjs/manage-custom-vars/manage-custom-vars.directive.js +++ /dev/null @@ -1,26 +0,0 @@ -/*! - * Matomo - free/libre analytics platform - * - * @link https://matomo.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - */ - -/** - * Usage: - *
- */ -(function () { - angular.module('piwikApp').directive('piwikManageCustomVars', piwikManageCustomVars); - - piwikManageCustomVars.$inject = ['piwik']; - - function piwikManageCustomVars(piwik){ - return { - restrict: 'A', - scope: {}, - templateUrl: 'plugins/CustomVariables/angularjs/manage-custom-vars/manage-custom-vars.directive.html?cb=' + piwik.cacheBuster, - controller: 'ManageCustomVarsController', - controllerAs: 'manageCustomVars' - }; - } -})(); \ No newline at end of file diff --git a/angularjs/manage-custom-vars/manage-custom-vars.model.js b/angularjs/manage-custom-vars/manage-custom-vars.model.js deleted file mode 100644 index 6ce717b..0000000 --- a/angularjs/manage-custom-vars/manage-custom-vars.model.js +++ /dev/null @@ -1,59 +0,0 @@ -/*! - * 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('manageCustomVarsModel', manageCustomVarsModel); - - manageCustomVarsModel.$inject = ['piwikApi']; - - function manageCustomVarsModel(piwikApi) { - - var model = { - customVariables : [], - extractions : [], - isLoading: false, - fetchUsages: fetchUsages, - hasCustomVariablesInGeneral: false, - hasAtLeastOneUsage: false, - numSlotsAvailable: 5, - }; - - return model; - - function fetchCustomVariables() { - return piwikApi.fetch({method: 'CustomVariables.getCustomVariables', period: 'year', date: 'today', filter_limit: 1}) - .then(function (customVariables) { - model.hasCustomVariablesInGeneral = (customVariables && customVariables.length > 0); - }); - } - - function fetchUsages() { - - model.isLoading = true; - - fetchCustomVariables().then(function () { - return piwikApi.fetch({method: 'CustomVariables.getUsagesOfSlots', filter_limit: '-1'}); - - }).then(function (customVariables) { - model.customVariables = customVariables; - - angular.forEach(customVariables, function (customVar) { - if (customVar.index > model.numSlotsAvailable) { - model.numSlotsAvailable = customVar.index; - } - - if (customVar.usages && customVar.usages.length > 0) { - model.hasAtLeastOneUsage = true; - } - }); - - })['finally'](function () { // .finally() is not IE8 compatible see https://github.com/angular/angular.js/commit/f078762d48d0d5d9796dcdf2cb0241198677582c - model.isLoading = false; - }); - } - - } -})(); \ No newline at end of file diff --git a/plugin.json b/plugin.json index a64efe3..8ed22cd 100644 --- a/plugin.json +++ b/plugin.json @@ -1,12 +1,12 @@ { "name": "CustomVariables", "description": "Categorise your visitors and actions with custom name-value pairs. Segment by these values and get more insights to draw the right conclusions.", - "version": "4.0.1", + "version": "4.1.0", "keywords": ["custom variables"], "license": "GPL v3+", "homepage": "https://matomo.org", "require": { - "matomo": ">=4.0.0-b1,<5.0.0-b1" + "matomo": ">=4.10.0-b1,<5.0.0-b1" }, "support": { "email": "hello@matomo.org", diff --git a/templates/manage.twig b/templates/manage.twig index e10e1ee..397e693 100644 --- a/templates/manage.twig +++ b/templates/manage.twig @@ -7,5 +7,5 @@ {% endblock %} {% block content %} -
+
{% endblock %} \ No newline at end of file diff --git a/tests/UI/expected-ui-screenshots/CustomVariables_manage.png b/tests/UI/expected-ui-screenshots/CustomVariables_manage.png index 5def12a..7a97026 100644 Binary files a/tests/UI/expected-ui-screenshots/CustomVariables_manage.png and b/tests/UI/expected-ui-screenshots/CustomVariables_manage.png differ diff --git a/vue/dist/CustomVariables.umd.js b/vue/dist/CustomVariables.umd.js new file mode 100644 index 0000000..e7c0d43 --- /dev/null +++ b/vue/dist/CustomVariables.umd.js @@ -0,0 +1,460 @@ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(require("CoreHome"), require("vue")); + else if(typeof define === 'function' && define.amd) + define(["CoreHome", ], factory); + else if(typeof exports === 'object') + exports["CustomVariables"] = factory(require("CoreHome"), require("vue")); + else + root["CustomVariables"] = factory(root["CoreHome"], root["Vue"]); +})((typeof self !== 'undefined' ? self : this), function(__WEBPACK_EXTERNAL_MODULE__19dc__, __WEBPACK_EXTERNAL_MODULE__8bbf__) { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = "plugins/CustomVariables/vue/dist/"; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = "fae3"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "19dc": +/***/ (function(module, exports) { + +module.exports = __WEBPACK_EXTERNAL_MODULE__19dc__; + +/***/ }), + +/***/ "8bbf": +/***/ (function(module, exports) { + +module.exports = __WEBPACK_EXTERNAL_MODULE__8bbf__; + +/***/ }), + +/***/ "fae3": +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +// ESM COMPAT FLAG +__webpack_require__.r(__webpack_exports__); + +// EXPORTS +__webpack_require__.d(__webpack_exports__, "ManageCustomVarsStore", function() { return /* reexport */ ManageCustomVars_store; }); +__webpack_require__.d(__webpack_exports__, "ManageCustomVars", function() { return /* reexport */ ManageCustomVars; }); + +// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/setPublicPath.js +// This file is imported into lib/wc client bundles. + +if (typeof window !== 'undefined') { + var currentScript = window.document.currentScript + if (false) { var getCurrentScript; } + + var src = currentScript && currentScript.src.match(/(.+\/)[^/]+\.js(\?.*)?$/) + if (src) { + __webpack_require__.p = src[1] // eslint-disable-line + } +} + +// Indicate to webpack that this file can be concatenated +/* harmony default export */ var setPublicPath = (null); + +// EXTERNAL MODULE: external "CoreHome" +var external_CoreHome_ = __webpack_require__("19dc"); + +// EXTERNAL MODULE: external {"commonjs":"vue","commonjs2":"vue","root":"Vue"} +var external_commonjs_vue_commonjs2_vue_root_Vue_ = __webpack_require__("8bbf"); + +// CONCATENATED MODULE: ./node_modules/@vue/cli-plugin-babel/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/vue-loader-v16/dist/templateLoader.js??ref--6!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader-v16/dist??ref--0-1!./plugins/CustomVariables/vue/src/ManageCustomVars/ManageCustomVars.vue?vue&type=template&id=ddf373e4 + +var _hoisted_1 = { + class: "manageCustomVars" +}; +var _hoisted_2 = ["innerHTML"]; +var _hoisted_3 = { + class: "index" +}; +var _hoisted_4 = ["title"]; +var _hoisted_5 = { + key: 0 +}; + +var _hoisted_6 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); + +var _hoisted_7 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); + +var _hoisted_8 = ["innerHTML"]; + +var _hoisted_9 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); + +var _hoisted_10 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); + +var _hoisted_11 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); + +var _hoisted_12 = ["textContent"]; +function render(_ctx, _cache, $props, $setup, $data, $options) { + var _component_EnrichedHeadline = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["resolveComponent"])("EnrichedHeadline"); + + var _component_ContentBlock = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["resolveComponent"])("ContentBlock"); + + var _directive_content_intro = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["resolveDirective"])("content-intro"); + + var _directive_content_table = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["resolveDirective"])("content-table"); + + var _directive_select_on_focus = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["resolveDirective"])("select-on-focus"); + + return Object(external_commonjs_vue_commonjs2_vue_root_Vue_["openBlock"])(), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementBlock"])("div", _hoisted_1, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["withDirectives"])(Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("div", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("h2", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createVNode"])(_component_EnrichedHeadline, { + "help-url": "https://matomo.org/docs/custom-variables/" + }, { + default: Object(external_commonjs_vue_commonjs2_vue_root_Vue_["withCtx"])(function () { + return [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('CustomVariables_CustomVariables')), 1)]; + }), + _: 1 + })]), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("p", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("span", { + innerHTML: _ctx.$sanitize(_ctx.translate('CustomVariables_ManageDescription', _ctx.siteName)) + }, null, 8, _hoisted_2)])], 512), [[_directive_content_intro]]), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["withDirectives"])(Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("div", { + class: "alert alert-info" + }, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('CustomVariables_SlotsReportIsGeneratedOverTime')), 513), [[external_commonjs_vue_commonjs2_vue_root_Vue_["vShow"], !_ctx.isLoading && _ctx.hasCustomVariablesInGeneral && !_ctx.hasAtLeastOneUsage]]), (Object(external_commonjs_vue_commonjs2_vue_root_Vue_["openBlock"])(true), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementBlock"])(external_commonjs_vue_commonjs2_vue_root_Vue_["Fragment"], null, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["renderList"])(_ctx.scopes, function (scope) { + return Object(external_commonjs_vue_commonjs2_vue_root_Vue_["openBlock"])(), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementBlock"])("div", { + key: scope.name + }, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createVNode"])(_component_ContentBlock, { + "content-title": _ctx.translate('CustomVariables_ScopeX', scope.name) + }, { + default: Object(external_commonjs_vue_commonjs2_vue_root_Vue_["withCtx"])(function () { + return [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["withDirectives"])(Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("table", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("thead", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("tr", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("th", null, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('CustomVariables_Index')), 1), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("th", null, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('CustomVariables_Usages')), 1)])]), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("tbody", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("tr", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["withDirectives"])(Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("td", { + colspan: "3" + }, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('General_Loading')), 513), [[external_commonjs_vue_commonjs2_vue_root_Vue_["vShow"], _ctx.isLoading]])]), (Object(external_commonjs_vue_commonjs2_vue_root_Vue_["openBlock"])(true), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementBlock"])(external_commonjs_vue_commonjs2_vue_root_Vue_["Fragment"], null, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["renderList"])(_ctx.customVariablesByScope[scope.value], function (customVariables, index) { + return Object(external_commonjs_vue_commonjs2_vue_root_Vue_["openBlock"])(), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementBlock"])("tr", { + key: index + }, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("td", _hoisted_3, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(customVariables.index), 1), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("td", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["withDirectives"])(Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("span", { + class: "unused" + }, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('CustomVariables_Unused')), 513), [[external_commonjs_vue_commonjs2_vue_root_Vue_["vShow"], customVariables.usages.length === 0]]), (Object(external_commonjs_vue_commonjs2_vue_root_Vue_["openBlock"])(true), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementBlock"])(external_commonjs_vue_commonjs2_vue_root_Vue_["Fragment"], null, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["renderList"])(_ctx.sortUsages(customVariables), function (cvar, cvarIndex) { + return Object(external_commonjs_vue_commonjs2_vue_root_Vue_["withDirectives"])((Object(external_commonjs_vue_commonjs2_vue_root_Vue_["openBlock"])(), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementBlock"])("span", { + key: cvarIndex + }, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("span", { + title: _ctx.translate('CustomVariables_UsageDetails', cvar.nb_visits ? cvar.nb_visits : 0, cvar.nb_actions ? cvar.nb_actions : 0) + }, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(cvar.name), 9, _hoisted_4), cvarIndex < customVariables.usages.length - 1 ? (Object(external_commonjs_vue_commonjs2_vue_root_Vue_["openBlock"])(), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementBlock"])("span", _hoisted_5, ", ")) : Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createCommentVNode"])("", true)], 512)), [[external_commonjs_vue_commonjs2_vue_root_Vue_["vShow"], customVariables.usages.length]]); + }), 128))])]); + }), 128))])], 512), [[_directive_content_table]])]; + }), + _: 2 + }, 1032, ["content-title"])]); + }), 128)), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["withDirectives"])(Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createVNode"])(_component_ContentBlock, { + id: "CustomVariablesCreateNewSlot", + "content-title": _ctx.translate('CustomVariables_CreateNewSlot') + }, { + default: Object(external_commonjs_vue_commonjs2_vue_root_Vue_["withCtx"])(function () { + return [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["withDirectives"])(Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("div", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("p", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('CustomVariables_CreatingCustomVariableTakesTime')) + " ", 1), _hoisted_6, _hoisted_7, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("span", { + innerHTML: _ctx.$sanitize(_ctx.currentAvailableCustomVariablesText) + }, null, 8, _hoisted_8), _hoisted_9, _hoisted_10, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(" " + Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('CustomVariables_ToCreateCustomVarExecute')) + " ", 1), _hoisted_11]), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["withDirectives"])(Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("pre", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("code", { + textContent: Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.setMaxCustomVariablesCmd) + }, null, 8, _hoisted_12)], 512), [[_directive_select_on_focus, {}]])], 512), [[external_commonjs_vue_commonjs2_vue_root_Vue_["vShow"], !_ctx.isLoading]])]; + }), + _: 1 + }, 8, ["content-title"]), [[external_commonjs_vue_commonjs2_vue_root_Vue_["vShow"], !_ctx.isLoading]])]); +} +// CONCATENATED MODULE: ./plugins/CustomVariables/vue/src/ManageCustomVars/ManageCustomVars.vue?vue&type=template&id=ddf373e4 + +// CONCATENATED MODULE: ./plugins/CustomVariables/vue/src/ManageCustomVars/ManageCustomVars.store.ts +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } + +function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } + +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } + +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + +function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } + +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + + + +var ManageCustomVars_store_ManageCustomVarsStore = /*#__PURE__*/function () { + function ManageCustomVarsStore() { + var _this = this; + + _classCallCheck(this, ManageCustomVarsStore); + + _defineProperty(this, "privateState", Object(external_commonjs_vue_commonjs2_vue_root_Vue_["reactive"])({ + customVariables: [], + isLoading: false, + hasCustomVariablesInGeneral: false, + hasAtLeastOneUsage: false, + numSlotsAvailable: 5 + })); + + _defineProperty(this, "state", Object(external_commonjs_vue_commonjs2_vue_root_Vue_["computed"])(function () { + return Object(external_commonjs_vue_commonjs2_vue_root_Vue_["readonly"])(_this.privateState); + })); + } + + _createClass(ManageCustomVarsStore, [{ + key: "init", + value: function init() { + return this.fetchUsages(); + } + }, { + key: "fetchCustomVariables", + value: function fetchCustomVariables() { + var _this2 = this; + + return external_CoreHome_["AjaxHelper"].fetch({ + method: 'CustomVariables.getCustomVariables', + period: 'year', + date: 'today', + filter_limit: 1 + }).then(function (customVariables) { + _this2.privateState.hasCustomVariablesInGeneral = (customVariables === null || customVariables === void 0 ? void 0 : customVariables.length) > 0; + }); + } + }, { + key: "fetchUsages", + value: function fetchUsages() { + var _this3 = this; + + this.privateState.isLoading = true; + return Promise.all([this.fetchCustomVariables(), external_CoreHome_["AjaxHelper"].fetch({ + method: 'CustomVariables.getUsagesOfSlots', + filter_limit: '-1' + })]).then(function (_ref) { + var _ref2 = _slicedToArray(_ref, 2), + customVariableUsages = _ref2[1]; + + _this3.privateState.customVariables = customVariableUsages; + customVariableUsages.forEach(function (customVar) { + if (customVar.index > _this3.state.value.numSlotsAvailable) { + _this3.privateState.numSlotsAvailable = customVar.index; + } + + if (customVar.usages && customVar.usages.length > 0) { + _this3.privateState.hasAtLeastOneUsage = true; + } + }); + }).finally(function () { + _this3.privateState.isLoading = false; + }); + } + }]); + + return ManageCustomVarsStore; +}(); + +/* harmony default export */ var ManageCustomVars_store = (new ManageCustomVars_store_ManageCustomVarsStore()); +// CONCATENATED MODULE: ./node_modules/@vue/cli-plugin-typescript/node_modules/cache-loader/dist/cjs.js??ref--14-0!./node_modules/babel-loader/lib!./node_modules/@vue/cli-plugin-typescript/node_modules/ts-loader??ref--14-2!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader-v16/dist??ref--0-1!./plugins/CustomVariables/vue/src/ManageCustomVars/ManageCustomVars.vue?vue&type=script&lang=ts +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || ManageCustomVarsvue_type_script_lang_ts_unsupportedIterableToArray(arr) || _nonIterableSpread(); } + +function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } + +function ManageCustomVarsvue_type_script_lang_ts_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return ManageCustomVarsvue_type_script_lang_ts_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return ManageCustomVarsvue_type_script_lang_ts_arrayLikeToArray(o, minLen); } + +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } + +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return ManageCustomVarsvue_type_script_lang_ts_arrayLikeToArray(arr); } + +function ManageCustomVarsvue_type_script_lang_ts_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } + + + + +/* harmony default export */ var ManageCustomVarsvue_type_script_lang_ts = (Object(external_commonjs_vue_commonjs2_vue_root_Vue_["defineComponent"])({ + components: { + EnrichedHeadline: external_CoreHome_["EnrichedHeadline"], + ContentBlock: external_CoreHome_["ContentBlock"] + }, + directives: { + ContentIntro: external_CoreHome_["ContentIntro"], + ContentTable: external_CoreHome_["ContentTable"], + SelectOnFocus: external_CoreHome_["SelectOnFocus"] + }, + data: function data() { + return { + siteName: external_CoreHome_["Matomo"].siteName, + scopes: [{ + value: 'visit', + name: Object(external_CoreHome_["translate"])('General_TrackingScopeVisit') + }, { + value: 'page', + name: Object(external_CoreHome_["translate"])('General_TrackingScopePage') + }] + }; + }, + created: function created() { + ManageCustomVars_store.init(); + }, + methods: { + sortUsages: function sortUsages(customVar) { + var result = _toConsumableArray(customVar.usages); + + result.sort(function (lhs, rhs) { + var rhsActions = "".concat(rhs.nb_actions); + var lhsActions = "".concat(lhs.nb_actions); + return parseInt(rhsActions, 10) - parseInt(lhsActions, 10); + }); + return result; + } + }, + computed: { + isLoading: function isLoading() { + return ManageCustomVars_store.state.value.isLoading; + }, + hasCustomVariablesInGeneral: function hasCustomVariablesInGeneral() { + return ManageCustomVars_store.state.value.hasCustomVariablesInGeneral; + }, + hasAtLeastOneUsage: function hasAtLeastOneUsage() { + return ManageCustomVars_store.state.value.hasAtLeastOneUsage; + }, + numSlotsAvailable: function numSlotsAvailable() { + return ManageCustomVars_store.state.value.numSlotsAvailable; + }, + customVariablesByScope: function customVariablesByScope() { + var result = {}; + ManageCustomVars_store.state.value.customVariables.forEach(function (customVar) { + result[customVar.scope] = result[customVar.scope] || []; + result[customVar.scope].push(customVar); + }); + return result; + }, + currentAvailableCustomVariablesText: function currentAvailableCustomVariablesText() { + return Object(external_CoreHome_["translate"])('CustomVariables_CurrentAvailableCustomVariables', "".concat(this.numSlotsAvailable, "")); + }, + setMaxCustomVariablesCmd: function setMaxCustomVariablesCmd() { + return "./console customvariables:set-max-custom-variables ".concat(this.numSlotsAvailable + 1); + } + } +})); +// CONCATENATED MODULE: ./plugins/CustomVariables/vue/src/ManageCustomVars/ManageCustomVars.vue?vue&type=script&lang=ts + +// CONCATENATED MODULE: ./plugins/CustomVariables/vue/src/ManageCustomVars/ManageCustomVars.vue + + + +ManageCustomVarsvue_type_script_lang_ts.render = render + +/* harmony default export */ var ManageCustomVars = (ManageCustomVarsvue_type_script_lang_ts); +// CONCATENATED MODULE: ./plugins/CustomVariables/vue/src/ManageCustomVars/ManageCustomVars.adapter.ts +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + + +/* harmony default export */ var ManageCustomVars_adapter = (Object(external_CoreHome_["createAngularJsAdapter"])({ + component: ManageCustomVars, + directiveName: 'piwikManageCustomVars' +})); +// CONCATENATED MODULE: ./plugins/CustomVariables/vue/src/index.ts +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + + + +// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/entry-lib-no-default.js + + + + +/***/ }) + +/******/ }); +}); +//# sourceMappingURL=CustomVariables.umd.js.map \ No newline at end of file diff --git a/vue/dist/CustomVariables.umd.min.js b/vue/dist/CustomVariables.umd.min.js new file mode 100644 index 0000000..68cfa43 --- /dev/null +++ b/vue/dist/CustomVariables.umd.min.js @@ -0,0 +1,14 @@ +(function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t(require("CoreHome"),require("vue")):"function"===typeof define&&define.amd?define(["CoreHome"],t):"object"===typeof exports?exports["CustomVariables"]=t(require("CoreHome"),require("vue")):e["CustomVariables"]=t(e["CoreHome"],e["Vue"])})("undefined"!==typeof self?self:this,(function(e,t){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(r,a,function(t){return e[t]}.bind(null,a));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="plugins/CustomVariables/vue/dist/",n(n.s="fae3")}({"19dc":function(t,n){t.exports=e},"8bbf":function(e,n){e.exports=t},fae3:function(e,t,n){"use strict";if(n.r(t),n.d(t,"ManageCustomVarsStore",(function(){return _})),n.d(t,"ManageCustomVars",(function(){return H})),"undefined"!==typeof window){var r=window.document.currentScript,a=r&&r.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);a&&(n.p=a[1])}var o=n("19dc"),l=n("8bbf"),i={class:"manageCustomVars"},c=["innerHTML"],s={class:"index"},u=["title"],b={key:0},m=Object(l["createElementVNode"])("br",null,null,-1),d=Object(l["createElementVNode"])("br",null,null,-1),f=["innerHTML"],p=Object(l["createElementVNode"])("br",null,null,-1),v=Object(l["createElementVNode"])("br",null,null,-1),O=Object(l["createElementVNode"])("br",null,null,-1),j=["textContent"];function h(e,t,n,r,a,o){var h=Object(l["resolveComponent"])("EnrichedHeadline"),g=Object(l["resolveComponent"])("ContentBlock"),y=Object(l["resolveDirective"])("content-intro"),V=Object(l["resolveDirective"])("content-table"),C=Object(l["resolveDirective"])("select-on-focus");return Object(l["openBlock"])(),Object(l["createElementBlock"])("div",i,[Object(l["withDirectives"])(Object(l["createElementVNode"])("div",null,[Object(l["createElementVNode"])("h2",null,[Object(l["createVNode"])(h,{"help-url":"https://matomo.org/docs/custom-variables/"},{default:Object(l["withCtx"])((function(){return[Object(l["createTextVNode"])(Object(l["toDisplayString"])(e.translate("CustomVariables_CustomVariables")),1)]})),_:1})]),Object(l["createElementVNode"])("p",null,[Object(l["createElementVNode"])("span",{innerHTML:e.$sanitize(e.translate("CustomVariables_ManageDescription",e.siteName))},null,8,c)])],512),[[y]]),Object(l["withDirectives"])(Object(l["createElementVNode"])("div",{class:"alert alert-info"},Object(l["toDisplayString"])(e.translate("CustomVariables_SlotsReportIsGeneratedOverTime")),513),[[l["vShow"],!e.isLoading&&e.hasCustomVariablesInGeneral&&!e.hasAtLeastOneUsage]]),(Object(l["openBlock"])(!0),Object(l["createElementBlock"])(l["Fragment"],null,Object(l["renderList"])(e.scopes,(function(t){return Object(l["openBlock"])(),Object(l["createElementBlock"])("div",{key:t.name},[Object(l["createVNode"])(g,{"content-title":e.translate("CustomVariables_ScopeX",t.name)},{default:Object(l["withCtx"])((function(){return[Object(l["withDirectives"])(Object(l["createElementVNode"])("table",null,[Object(l["createElementVNode"])("thead",null,[Object(l["createElementVNode"])("tr",null,[Object(l["createElementVNode"])("th",null,Object(l["toDisplayString"])(e.translate("CustomVariables_Index")),1),Object(l["createElementVNode"])("th",null,Object(l["toDisplayString"])(e.translate("CustomVariables_Usages")),1)])]),Object(l["createElementVNode"])("tbody",null,[Object(l["createElementVNode"])("tr",null,[Object(l["withDirectives"])(Object(l["createElementVNode"])("td",{colspan:"3"},Object(l["toDisplayString"])(e.translate("General_Loading")),513),[[l["vShow"],e.isLoading]])]),(Object(l["openBlock"])(!0),Object(l["createElementBlock"])(l["Fragment"],null,Object(l["renderList"])(e.customVariablesByScope[t.value],(function(t,n){return Object(l["openBlock"])(),Object(l["createElementBlock"])("tr",{key:n},[Object(l["createElementVNode"])("td",s,Object(l["toDisplayString"])(t.index),1),Object(l["createElementVNode"])("td",null,[Object(l["withDirectives"])(Object(l["createElementVNode"])("span",{class:"unused"},Object(l["toDisplayString"])(e.translate("CustomVariables_Unused")),513),[[l["vShow"],0===t.usages.length]]),(Object(l["openBlock"])(!0),Object(l["createElementBlock"])(l["Fragment"],null,Object(l["renderList"])(e.sortUsages(t),(function(n,r){return Object(l["withDirectives"])((Object(l["openBlock"])(),Object(l["createElementBlock"])("span",{key:r},[Object(l["createElementVNode"])("span",{title:e.translate("CustomVariables_UsageDetails",n.nb_visits?n.nb_visits:0,n.nb_actions?n.nb_actions:0)},Object(l["toDisplayString"])(n.name),9,u),re.length)&&(t=e.length);for(var n=0,r=new Array(t);n0}))}},{key:"fetchUsages",value:function(){var e=this;return this.privateState.isLoading=!0,Promise.all([this.fetchCustomVariables(),o["AjaxHelper"].fetch({method:"CustomVariables.getUsagesOfSlots",filter_limit:"-1"})]).then((function(t){var n=g(t,2),r=n[1];e.privateState.customVariables=r,r.forEach((function(t){t.index>e.state.value.numSlotsAvailable&&(e.privateState.numSlotsAvailable=t.index),t.usages&&t.usages.length>0&&(e.privateState.hasAtLeastOneUsage=!0)}))})).finally((function(){e.privateState.isLoading=!1}))}}]),e}(),_=new A;function D(e){return I(e)||B(e)||T(e)||L()}function L(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function T(e,t){if(e){if("string"===typeof e)return M(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?M(e,t):void 0}}function B(e){if("undefined"!==typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function I(e){if(Array.isArray(e))return M(e)}function M(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n".concat(this.numSlotsAvailable,""))},setMaxCustomVariablesCmd:function(){return"./console customvariables:set-max-custom-variables ".concat(this.numSlotsAvailable+1)}}});U.render=h;var H=U; +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */Object(o["createAngularJsAdapter"])({component:H,directiveName:"piwikManageCustomVars"})}})})); +//# sourceMappingURL=CustomVariables.umd.min.js.map \ No newline at end of file diff --git a/vue/dist/umd.metadata.json b/vue/dist/umd.metadata.json new file mode 100644 index 0000000..9ecfcc0 --- /dev/null +++ b/vue/dist/umd.metadata.json @@ -0,0 +1,5 @@ +{ + "dependsOn": [ + "CoreHome" + ] +} \ No newline at end of file diff --git a/vue/src/ManageCustomVars/ManageCustomVars.adapter.ts b/vue/src/ManageCustomVars/ManageCustomVars.adapter.ts new file mode 100644 index 0000000..fd1c5d4 --- /dev/null +++ b/vue/src/ManageCustomVars/ManageCustomVars.adapter.ts @@ -0,0 +1,14 @@ +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +import { createAngularJsAdapter } from 'CoreHome'; +import ManageCustomVars from './ManageCustomVars.vue'; + +export default createAngularJsAdapter({ + component: ManageCustomVars, + directiveName: 'piwikManageCustomVars', +}); diff --git a/angularjs/manage-custom-vars/manage-custom-vars.directive.less b/vue/src/ManageCustomVars/ManageCustomVars.less similarity index 100% rename from angularjs/manage-custom-vars/manage-custom-vars.directive.less rename to vue/src/ManageCustomVars/ManageCustomVars.less diff --git a/vue/src/ManageCustomVars/ManageCustomVars.store.ts b/vue/src/ManageCustomVars/ManageCustomVars.store.ts new file mode 100644 index 0000000..596cf62 --- /dev/null +++ b/vue/src/ManageCustomVars/ManageCustomVars.store.ts @@ -0,0 +1,75 @@ +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +import { + reactive, + computed, + readonly, +} from 'vue'; +import { AjaxHelper } from 'CoreHome'; +import { CustomVariableUsage } from '../types'; + +interface CustomVarsStoreState { + customVariables: CustomVariableUsage[]; + isLoading: boolean; + hasCustomVariablesInGeneral: boolean; + hasAtLeastOneUsage: boolean; + numSlotsAvailable: number; +} + +class ManageCustomVarsStore { + private privateState = reactive({ + customVariables: [], + isLoading: false, + hasCustomVariablesInGeneral: false, + hasAtLeastOneUsage: false, + numSlotsAvailable: 5, + }); + + readonly state = computed(() => readonly(this.privateState)); + + init(): Promise { + return this.fetchUsages(); + } + + fetchCustomVariables(): Promise { + return AjaxHelper.fetch({ + method: 'CustomVariables.getCustomVariables', + period: 'year', + date: 'today', + filter_limit: 1, + }).then((customVariables) => { + this.privateState.hasCustomVariablesInGeneral = customVariables?.length > 0; + }); + } + + fetchUsages(): Promise { + this.privateState.isLoading = true; + return Promise.all([ + this.fetchCustomVariables(), + AjaxHelper.fetch({ + method: 'CustomVariables.getUsagesOfSlots', + filter_limit: '-1', + }), + ]).then(([, customVariableUsages]) => { + this.privateState.customVariables = customVariableUsages as CustomVariableUsage[]; + (customVariableUsages as CustomVariableUsage[]).forEach((customVar) => { + if (customVar.index > this.state.value.numSlotsAvailable) { + this.privateState.numSlotsAvailable = customVar.index; + } + + if (customVar.usages && customVar.usages.length > 0) { + this.privateState.hasAtLeastOneUsage = true; + } + }); + }).finally(() => { + this.privateState.isLoading = false; + }); + } +} + +export default new ManageCustomVarsStore(); diff --git a/vue/src/ManageCustomVars/ManageCustomVars.vue b/vue/src/ManageCustomVars/ManageCustomVars.vue new file mode 100644 index 0000000..3361f5c --- /dev/null +++ b/vue/src/ManageCustomVars/ManageCustomVars.vue @@ -0,0 +1,185 @@ + + + + + diff --git a/vue/src/index.ts b/vue/src/index.ts new file mode 100644 index 0000000..410da49 --- /dev/null +++ b/vue/src/index.ts @@ -0,0 +1,11 @@ +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +import './ManageCustomVars/ManageCustomVars.adapter'; + +export { default as ManageCustomVarsStore } from './ManageCustomVars/ManageCustomVars.store'; +export { default as ManageCustomVars } from './ManageCustomVars/ManageCustomVars.vue'; diff --git a/vue/src/types.ts b/vue/src/types.ts new file mode 100644 index 0000000..c5f9abb --- /dev/null +++ b/vue/src/types.ts @@ -0,0 +1,20 @@ +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +interface CustomVariableUsageRow { + name: string; + nb_actions: number|string; + nb_visits: number|string; +} + +interface CustomVariableUsage { + index: number; + scope: string; + usages: CustomVariableUsageRow[]; +} + +export { CustomVariableUsage };