Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | /** |
| 4 | * © OpenCORD |
| 5 | * |
| 6 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 7 | * |
| 8 | * Created by teone on 3/24/16. |
| 9 | */ |
| 10 | |
| 11 | (function () { |
| 12 | 'use strict'; |
| 13 | |
| 14 | /** |
| 15 | * @ngdoc overview |
| 16 | * @name xos.uiComponents |
| 17 | * @description |
| 18 | * # xos.uiComponents |
| 19 | * A collection of UI components useful for Dashboard development. <br/> |
| 20 | * Currently available components are: |
| 21 | * - [xosAlert](/#/module/xos.uiComponents.directive:xosAlert) |
| 22 | * - [xosForm](/#/module/xos.uiComponents.directive:xosForm) |
| 23 | * - [xosPagination](/#/module/xos.uiComponents.directive:xosPagination) |
| 24 | * - [xosSmartTable](/#/module/xos.uiComponents.directive:xosSmartTable) |
| 25 | * - [xosTable](/#/module/xos.uiComponents.directive:xosTable) |
| 26 | * - [xosValidation](/#/module/xos.uiComponents.directive:xosValidation) |
| 27 | **/ |
| 28 | |
| 29 | angular.module('xos.uiComponents', ['chart.js', 'RecursionHelper']); |
| 30 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 31 | //# sourceMappingURL=../maps/ui_components/ui-components.module.js.map |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 32 | |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 33 | 'use strict'; |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * © OpenCORD |
| 37 | * |
| 38 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 39 | * |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 40 | * Created by teone on 3/24/16. |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 41 | */ |
| 42 | |
| 43 | (function () { |
| 44 | 'use strict'; |
| 45 | |
| 46 | angular.module('xos.uiComponents') |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 47 | |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 48 | /** |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 49 | * @ngdoc directive |
| 50 | * @name xos.uiComponents.directive:xosSmartTable |
| 51 | * @link xos.uiComponents.directive:xosTable xosTable |
| 52 | * @link xos.uiComponents.directive:xosForm xosForm |
| 53 | * @restrict E |
| 54 | * @description The xos-table directive |
| 55 | * @param {Object} config The configuration for the component, |
| 56 | * it is composed by the name of an angular [$resource](https://docs.angularjs.org/api/ngResource/service/$resource) |
| 57 | * and an array of fields that shouldn't be printed. |
| 58 | * ``` |
| 59 | * { |
| 60 | resource: 'Users', |
| 61 | hiddenFields: [] |
| 62 | } |
| 63 | * ``` |
| 64 | * @scope |
| 65 | * @example |
| 66 | <example module="sampleSmartTable"> |
| 67 | <file name="index.html"> |
| 68 | <div ng-controller="SampleCtrl as vm"> |
| 69 | <xos-smart-table config="vm.config"></xos-smart-table> |
| 70 | </div> |
| 71 | </file> |
| 72 | <file name="script.js"> |
| 73 | angular.module('sampleSmartTable', ['xos.uiComponents', 'ngResource', 'ngMockE2E']) |
| 74 | // This is only for documentation purpose |
| 75 | .run(function($httpBackend, _){ |
| 76 | let datas = [{id: 1, name: 'Jhon', surname: 'Doe'}]; |
| 77 | let count = 1; |
| 78 | let paramsUrl = new RegExp(/\/test\/(.+)/); |
| 79 | $httpBackend.whenDELETE(paramsUrl, undefined, ['id']).respond((method, url, data, headers, params) => { |
| 80 | data = angular.fromJson(data); |
| 81 | let id = url.match(paramsUrl)[1]; |
| 82 | _.remove(datas, (d) => { |
| 83 | return d.id === parseInt(id); |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 84 | }) |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 85 | return [204]; |
| 86 | }); |
| 87 | $httpBackend.whenGET('/test').respond(200, datas) |
| 88 | $httpBackend.whenPOST('/test').respond((method, url, data) => { |
| 89 | data = angular.fromJson(data); |
| 90 | data.id = ++count; |
| 91 | datas.push(data); |
| 92 | return [201, data, {}]; |
| 93 | }); |
| 94 | }) |
| 95 | .factory('_', function($window){ |
| 96 | return $window._; |
| 97 | }) |
| 98 | .service('SampleResource', function($resource){ |
| 99 | return $resource('/test/:id', {id: '@id'}); |
| 100 | }) |
| 101 | // End of documentation purpose, example start |
| 102 | .controller('SampleCtrl', function(){ |
| 103 | this.config = { |
| 104 | resource: 'SampleResource' |
| 105 | }; |
| 106 | }); |
| 107 | </file> |
| 108 | </example> |
| 109 | */ |
| 110 | |
| 111 | .component('xosSmartTable', { |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 112 | restrict: 'E', |
| 113 | bindings: { |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 114 | config: '=' |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 115 | }, |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 116 | template: '\n <div class="row" ng-show="vm.data.length > 0">\n <div class="col-xs-12 text-right">\n <a href="" class="btn btn-success" ng-click="vm.createItem()">\n Add\n </a>\n </div>\n </div>\n <div class="row">\n <div class="col-xs-12 table-responsive">\n <xos-table config="vm.tableConfig" data="vm.data"></xos-table>\n </div>\n </div>\n <div class="panel panel-default" ng-show="vm.detailedItem">\n <div class="panel-heading">\n <div class="row">\n <div class="col-xs-11">\n <h3 class="panel-title" ng-show="vm.detailedItem.id">Update {{vm.config.resource}} {{vm.detailedItem.id}}</h3>\n <h3 class="panel-title" ng-show="!vm.detailedItem.id">Create {{vm.config.resource}} item</h3>\n </div>\n <div class="col-xs-1">\n <a href="" ng-click="vm.cleanForm()">\n <i class="glyphicon glyphicon-remove pull-right"></i>\n </a>\n </div>\n </div>\n </div>\n <div class="panel-body">\n <xos-form config="vm.formConfig" ng-model="vm.detailedItem"></xos-form>\n </div>\n </div>\n <xos-alert config="{type: \'success\', closeBtn: true}" show="vm.responseMsg">{{vm.responseMsg}}</xos-alert>\n <xos-alert config="{type: \'danger\', closeBtn: true}" show="vm.responseErr">{{vm.responseErr}}</xos-alert>\n ', |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 117 | bindToController: true, |
| 118 | controllerAs: 'vm', |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 119 | controller: ["$injector", "LabelFormatter", "_", "XosFormHelpers", function controller($injector, LabelFormatter, _, XosFormHelpers) { |
| 120 | var _this = this; |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 121 | |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 122 | // TODO |
| 123 | // - Validate the config (what if resource does not exist?) |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 124 | |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 125 | // NOTE |
| 126 | // Corner case |
| 127 | // - if response is empty, how can we generate a form ? |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 128 | |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 129 | this.responseMsg = false; |
| 130 | this.responseErr = false; |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 131 | |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 132 | this.tableConfig = { |
| 133 | columns: [], |
| 134 | actions: [{ |
| 135 | label: 'delete', |
| 136 | icon: 'remove', |
| 137 | cb: function cb(item) { |
| 138 | _this.Resource.delete({ id: item.id }).$promise.then(function () { |
| 139 | _.remove(_this.data, function (d) { |
| 140 | return d.id === item.id; |
| 141 | }); |
| 142 | _this.responseMsg = _this.config.resource + ' with id ' + item.id + ' successfully deleted'; |
| 143 | }).catch(function (err) { |
| 144 | _this.responseErr = err.data.detail || 'Error while deleting ' + _this.config.resource + ' with id ' + item.id; |
| 145 | }); |
| 146 | }, |
| 147 | color: 'red' |
| 148 | }, { |
| 149 | label: 'details', |
| 150 | icon: 'search', |
| 151 | cb: function cb(item) { |
| 152 | _this.detailedItem = item; |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 153 | } |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 154 | }], |
| 155 | classes: 'table table-striped table-bordered table-responsive', |
| 156 | filter: 'field', |
| 157 | order: true, |
| 158 | pagination: { |
| 159 | pageSize: 10 |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 160 | } |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 161 | }; |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 162 | |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 163 | this.formConfig = { |
| 164 | exclude: this.config.hiddenFields, |
| 165 | fields: {}, |
| 166 | formName: this.config.resource + 'Form', |
| 167 | actions: [{ |
| 168 | label: 'Save', |
| 169 | icon: 'ok', |
| 170 | cb: function cb(item) { |
| 171 | var p = void 0; |
| 172 | var isNew = true; |
| 173 | |
| 174 | if (item.id) { |
| 175 | p = item.$update(); |
| 176 | isNew = false; |
| 177 | } else { |
| 178 | p = item.$save(); |
| 179 | } |
| 180 | |
| 181 | p.then(function (res) { |
| 182 | if (isNew) { |
| 183 | _this.data.push(angular.copy(res)); |
| 184 | } |
| 185 | delete _this.detailedItem; |
| 186 | _this.responseMsg = _this.config.resource + ' with id ' + item.id + ' successfully saved'; |
| 187 | }).catch(function (err) { |
| 188 | _this.responseErr = err.data.detail || 'Error while saving ' + _this.config.resource + ' with id ' + item.id; |
| 189 | }); |
| 190 | }, |
| 191 | class: 'success' |
| 192 | }] |
| 193 | }; |
| 194 | |
| 195 | this.cleanForm = function () { |
| 196 | delete _this.detailedItem; |
| 197 | }; |
| 198 | |
| 199 | this.createItem = function () { |
| 200 | _this.detailedItem = new _this.Resource(); |
| 201 | }; |
| 202 | |
| 203 | this.Resource = $injector.get(this.config.resource); |
| 204 | |
| 205 | var getData = function getData() { |
| 206 | _this.Resource.query().$promise.then(function (res) { |
| 207 | |
| 208 | if (!res[0]) { |
| 209 | _this.data = res; |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | var item = res[0]; |
| 214 | var props = Object.keys(item); |
| 215 | |
| 216 | _.remove(props, function (p) { |
| 217 | return p === 'id' || p === 'validators'; |
| 218 | }); |
| 219 | |
| 220 | // TODO move out cb, non sense triggering a lot of times |
| 221 | if (angular.isArray(_this.config.hiddenFields)) { |
| 222 | props = _.difference(props, _this.config.hiddenFields); |
| 223 | } |
| 224 | |
| 225 | props.forEach(function (p) { |
| 226 | var fieldConfig = { |
| 227 | label: LabelFormatter.format(p), |
| 228 | prop: p |
| 229 | }; |
| 230 | |
| 231 | fieldConfig.type = XosFormHelpers._getFieldFormat(item[p]); |
| 232 | |
| 233 | _this.tableConfig.columns.push(fieldConfig); |
| 234 | }); |
| 235 | |
| 236 | // build form structure |
| 237 | // TODO move in a pure function for testing purposes |
| 238 | props.forEach(function (p, i) { |
| 239 | _this.formConfig.fields[p] = { |
| 240 | label: LabelFormatter.format(p).replace(':', ''), |
| 241 | type: XosFormHelpers._getFieldFormat(item[p]) |
| 242 | }; |
| 243 | }); |
| 244 | _this.data = res; |
| 245 | }); |
| 246 | }; |
| 247 | |
| 248 | getData(); |
| 249 | }] |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 250 | }); |
| 251 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 252 | //# sourceMappingURL=../../../maps/ui_components/smartComponents/smartTable/smartTable.component.js.map |
| 253 | |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 254 | 'use strict'; |
| 255 | |
| 256 | /** |
| 257 | * © OpenCORD |
| 258 | * |
| 259 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 260 | * |
| 261 | * Created by teone on 4/15/16. |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 262 | */ |
| 263 | |
| 264 | (function () { |
| 265 | 'use strict'; |
| 266 | |
| 267 | angular.module('xos.uiComponents') |
| 268 | |
| 269 | /** |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 270 | * @ngdoc directive |
| 271 | * @name xos.uiComponents.directive:xosValidation |
| 272 | * @restrict E |
| 273 | * @description The xos-validation directive |
| 274 | * @param {Object} errors The error object |
| 275 | * @element ANY |
| 276 | * @scope |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 277 | * @example |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 278 | <example module="sampleValidation"> |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 279 | <file name="index.html"> |
| 280 | <div ng-controller="SampleCtrl as vm"> |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 281 | <div class="row"> |
| 282 | <div class="col-xs-12"> |
| 283 | <label>Set an error type:</label> |
| 284 | </div> |
| 285 | <div class="col-xs-2"> |
| 286 | <a class="btn" |
| 287 | ng-click="vm.field.$error.required = !vm.field.$error.required" |
| 288 | ng-class="{'btn-default': !vm.field.$error.required, 'btn-success': vm.field.$error.required}"> |
| 289 | Required |
| 290 | </a> |
| 291 | </div> |
| 292 | <div class="col-xs-2"> |
| 293 | <a class="btn" |
| 294 | ng-click="vm.field.$error.email = !vm.field.$error.email" |
| 295 | ng-class="{'btn-default': !vm.field.$error.email, 'btn-success': vm.field.$error.email}"> |
| 296 | Email |
| 297 | </a> |
| 298 | </div> |
| 299 | <div class="col-xs-2"> |
| 300 | <a class="btn" |
| 301 | ng-click="vm.field.$error.minlength = !vm.field.$error.minlength" |
| 302 | ng-class="{'btn-default': !vm.field.$error.minlength, 'btn-success': vm.field.$error.minlength}"> |
| 303 | Min Length |
| 304 | </a> |
| 305 | </div> |
| 306 | <div class="col-xs-2"> |
| 307 | <a class="btn" |
| 308 | ng-click="vm.field.$error.maxlength = !vm.field.$error.maxlength" |
| 309 | ng-class="{'btn-default': !vm.field.$error.maxlength, 'btn-success': vm.field.$error.maxlength}"> |
| 310 | Max Length |
| 311 | </a> |
| 312 | </div> |
| 313 | </div> |
| 314 | <xos-validation field ="vm.field" form = "vm.form"></xos-validation> |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 315 | </div> |
| 316 | </file> |
| 317 | <file name="script.js"> |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 318 | angular.module('sampleValidation', ['xos.uiComponents']) |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 319 | .controller('SampleCtrl', function(){ |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 320 | this.field = { |
| 321 | $error: {} |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 322 | }; |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 323 | this.form= { |
| 324 | $submitted:true |
| 325 | } |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 326 | }); |
| 327 | </file> |
| 328 | </example> |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 329 | */ |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 330 | |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 331 | .component('xosValidation', { |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 332 | restrict: 'E', |
| 333 | bindings: { |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 334 | field: '=', |
| 335 | form: '=' |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 336 | }, |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 337 | template: '\n <div ng-cloak>\n <xos-alert config="vm.config" show="vm.field.$error.required !== undefined && vm.field.$error.required !== false && (vm.field.$touched || vm.form.$submitted)">\n Field required\n </xos-alert>\n <xos-alert config="vm.config" show="vm.field.$error.email !== undefined && vm.field.$error.email !== false && (vm.field.$touched || vm.form.$submitted)">\n This is not a valid email\n </xos-alert>\n <xos-alert config="vm.config" show="vm.field.$error.minlength !== undefined && vm.field.$error.minlength !== false && (vm.field.$touched || vm.form.$submitted)">\n Too short\n </xos-alert>\n <xos-alert config="vm.config" show="vm.field.$error.maxlength !== undefined && vm.field.$error.maxlength !== false && (vm.field.$touched || vm.form.$submitted)">\n Too long\n </xos-alert>\n <xos-alert config="vm.config" show="vm.field.$error.custom !== undefined && vm.field.$error.custom !== false && (vm.field.$touched || vm.form.$submitted)">\n Field invalid\n </xos-alert>\n </div>\n ', |
| 338 | transclude: true, |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 339 | bindToController: true, |
| 340 | controllerAs: 'vm', |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 341 | controller: function controller() { |
| 342 | this.config = { |
| 343 | type: 'danger' |
| 344 | }; |
| 345 | } |
| 346 | }); |
| 347 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 348 | //# sourceMappingURL=../../../maps/ui_components/dumbComponents/validation/validation.component.js.map |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 349 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 350 | 'use strict'; |
| 351 | |
| 352 | /** |
| 353 | * © OpenCORD |
| 354 | * |
| 355 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 356 | * |
| 357 | * Created by teone on 3/24/16. |
| 358 | */ |
| 359 | |
| 360 | (function () { |
| 361 | 'use strict'; |
| 362 | |
| 363 | angular.module('xos.uiComponents') |
| 364 | /** |
| 365 | * @ngdoc directive |
| 366 | * @name xos.uiComponents.directive:xosSmartPie |
| 367 | * @restrict E |
| 368 | * @description The xos-table directive |
| 369 | * @param {Object} config The configuration for the component, |
| 370 | * it is composed by the name of an angular [$resource](https://docs.angularjs.org/api/ngResource/service/$resource) |
| 371 | * and a field name that is used to group the data. |
| 372 | * ``` |
| 373 | * { |
| 374 | resource: 'Users', |
| 375 | groupBy: 'fieldName', |
| 376 | classes: 'my-custom-class', |
| 377 | labelFormatter: (labels) => { |
| 378 | // here you can format your label, |
| 379 | // you should return an array with the same order |
| 380 | return labels; |
| 381 | } |
| 382 | } |
| 383 | * ``` |
| 384 | * @scope |
| 385 | * @example |
| 386 | |
| 387 | Displaying Local data |
| 388 | <example module="sampleSmartPieLocal"> |
| 389 | <file name="index.html"> |
| 390 | <div ng-controller="SampleCtrlLocal as vm"> |
| 391 | <xos-smart-pie config="vm.configLocal"></xos-smart-pie> |
| 392 | </div> |
| 393 | </file> |
| 394 | <file name="script.js"> |
| 395 | angular.module('sampleSmartPieLocal', ['xos.uiComponents']) |
| 396 | .factory('_', function($window){ |
| 397 | return $window._; |
| 398 | }) |
| 399 | .controller('SampleCtrlLocal', function($timeout){ |
| 400 | |
| 401 | this.datas = [ |
| 402 | {id: 1, first_name: 'Jon', last_name: 'aaa', category: 2}, |
| 403 | {id: 2, first_name: 'Danaerys', last_name: 'Targaryen', category: 1}, |
| 404 | {id: 3, first_name: 'Aria', last_name: 'Stark', category: 2} |
| 405 | ]; |
| 406 | this.configLocal = { |
| 407 | data: [], |
| 408 | groupBy: 'category', |
| 409 | classes: 'local', |
| 410 | labelFormatter: (labels) => { |
| 411 | return labels.map(l => l === '1' ? 'North' : 'Dragon'); |
| 412 | } |
| 413 | }; |
| 414 | |
| 415 | $timeout(() => { |
| 416 | // this need to be triggered in this way just because of ngDoc, |
| 417 | // otherwise you can assign data directly in the config |
| 418 | this.configLocal.data = this.datas; |
| 419 | }, 1) |
| 420 | }); |
| 421 | </file> |
| 422 | </example> |
| 423 | Fetching data from API |
| 424 | <example module="sampleSmartPieResource"> |
| 425 | <file name="index.html"> |
| 426 | <div ng-controller="SampleCtrl as vm"> |
| 427 | <xos-smart-pie config="vm.config"></xos-smart-pie> |
| 428 | </div> |
| 429 | </file> |
| 430 | <file name="script.js"> |
| 431 | angular.module('sampleSmartPieResource', ['xos.uiComponents', 'ngResource', 'ngMockE2E']) |
| 432 | .controller('SampleCtrl', function(){ |
| 433 | this.config = { |
| 434 | resource: 'SampleResource', |
| 435 | groupBy: 'category', |
| 436 | classes: 'resource', |
| 437 | labelFormatter: (labels) => { |
| 438 | return labels.map(l => l === '1' ? 'North' : 'Dragon'); |
| 439 | } |
| 440 | }; |
| 441 | }); |
| 442 | </file> |
| 443 | <file name="backendPoll.js"> |
| 444 | angular.module('sampleSmartPieResource') |
| 445 | .run(function($httpBackend, _){ |
| 446 | let datas = [ |
| 447 | {id: 1, first_name: 'Jon', last_name: 'Snow', category: 1}, |
| 448 | {id: 2, first_name: 'Danaerys', last_name: 'Targaryen', category: 2}, |
| 449 | {id: 3, first_name: 'Aria', last_name: 'Stark', category: 1} |
| 450 | ]; |
| 451 | $httpBackend.whenGET('/test').respond(200, datas) |
| 452 | }) |
| 453 | .factory('_', function($window){ |
| 454 | return $window._; |
| 455 | }) |
| 456 | .service('SampleResource', function($resource){ |
| 457 | return $resource('/test/:id', {id: '@id'}); |
| 458 | }) |
| 459 | </file> |
| 460 | </example> |
| 461 | Polling data from API |
| 462 | <example module="sampleSmartPiePoll"> |
| 463 | <file name="index.html"> |
| 464 | <div ng-controller="SampleCtrl as vm"> |
| 465 | <xos-smart-pie config="vm.config"></xos-smart-pie> |
| 466 | </div> |
| 467 | </file> |
| 468 | <file name="script.js"> |
| 469 | angular.module('sampleSmartPiePoll', ['xos.uiComponents', 'ngResource', 'ngMockE2E']) |
| 470 | .controller('SampleCtrl', function(){ |
| 471 | this.config = { |
| 472 | resource: 'SampleResource', |
| 473 | groupBy: 'category', |
| 474 | poll: 2, |
| 475 | labelFormatter: (labels) => { |
| 476 | return labels.map(l => l === '1' ? 'Active' : 'Banned'); |
| 477 | } |
| 478 | }; |
| 479 | }); |
| 480 | </file> |
| 481 | <file name="backend.js"> |
| 482 | angular.module('sampleSmartPiePoll') |
| 483 | .run(function($httpBackend, _){ |
| 484 | let mock = [ |
| 485 | [ |
| 486 | {id: 1, first_name: 'Jon', last_name: 'Snow', category: 1}, |
| 487 | {id: 2, first_name: 'Danaerys', last_name: 'Targaryen', category: 2}, |
| 488 | {id: 3, first_name: 'Aria', last_name: 'Stark', category: 1}, |
| 489 | {id: 3, first_name: 'Tyrion', last_name: 'Lannister', category: 1} |
| 490 | ], |
| 491 | [ |
| 492 | {id: 1, first_name: 'Jon', last_name: 'Snow', category: 1}, |
| 493 | {id: 2, first_name: 'Danaerys', last_name: 'Targaryen', category: 2}, |
| 494 | {id: 3, first_name: 'Aria', last_name: 'Stark', category: 2}, |
| 495 | {id: 3, first_name: 'Tyrion', last_name: 'Lannister', category: 2} |
| 496 | ], |
| 497 | [ |
| 498 | {id: 1, first_name: 'Jon', last_name: 'Snow', category: 1}, |
| 499 | {id: 2, first_name: 'Danaerys', last_name: 'Targaryen', category: 2}, |
| 500 | {id: 3, first_name: 'Aria', last_name: 'Stark', category: 1}, |
| 501 | {id: 3, first_name: 'Tyrion', last_name: 'Lannister', category: 2} |
| 502 | ] |
| 503 | ]; |
| 504 | $httpBackend.whenGET('/test').respond(function(method, url, data, headers, params) { |
| 505 | return [200, mock[Math.round(Math.random() * 3)]]; |
| 506 | }); |
| 507 | }) |
| 508 | .factory('_', function($window){ |
| 509 | return $window._; |
| 510 | }) |
| 511 | .service('SampleResource', function($resource){ |
| 512 | return $resource('/test/:id', {id: '@id'}); |
| 513 | }) |
| 514 | </file> |
| 515 | </example> |
| 516 | */ |
| 517 | .component('xosSmartPie', { |
| 518 | restrict: 'E', |
| 519 | bindings: { |
| 520 | config: '=' |
| 521 | }, |
| 522 | template: '\n <canvas\n class="chart chart-pie {{vm.config.classes}}"\n chart-data="vm.data" chart-labels="vm.labels"\n chart-legend="{{vm.config.legend}}">\n </canvas>\n ', |
| 523 | bindToController: true, |
| 524 | controllerAs: 'vm', |
| 525 | controller: ["$injector", "$interval", "$scope", "$timeout", "_", function controller($injector, $interval, $scope, $timeout, _) { |
| 526 | var _this = this; |
| 527 | |
| 528 | if (!this.config.resource && !this.config.data) { |
| 529 | throw new Error('[xosSmartPie] Please provide a resource or an array of data in the configuration'); |
| 530 | } |
| 531 | |
| 532 | var groupData = function groupData(data) { |
| 533 | return _.groupBy(data, _this.config.groupBy); |
| 534 | }; |
| 535 | var formatData = function formatData(data) { |
| 536 | return _.reduce(Object.keys(data), function (list, group) { |
| 537 | return list.concat(data[group].length); |
| 538 | }, []); |
| 539 | }; |
| 540 | var formatLabels = function formatLabels(data) { |
| 541 | return angular.isFunction(_this.config.labelFormatter) ? _this.config.labelFormatter(Object.keys(data)) : Object.keys(data); |
| 542 | }; |
| 543 | |
| 544 | var prepareData = function prepareData(data) { |
| 545 | // group data |
| 546 | var grouped = groupData(data); |
| 547 | _this.data = formatData(grouped); |
| 548 | // create labels |
| 549 | _this.labels = formatLabels(grouped); |
| 550 | }; |
| 551 | |
| 552 | if (this.config.resource) { |
| 553 | (function () { |
| 554 | |
| 555 | _this.Resource = $injector.get(_this.config.resource); |
| 556 | var getData = function getData() { |
| 557 | _this.Resource.query().$promise.then(function (res) { |
| 558 | |
| 559 | if (!res[0]) { |
| 560 | return; |
| 561 | } |
| 562 | |
| 563 | prepareData(res); |
| 564 | }); |
| 565 | }; |
| 566 | |
| 567 | getData(); |
| 568 | |
| 569 | if (_this.config.poll) { |
| 570 | $interval(function () { |
| 571 | getData(); |
| 572 | }, _this.config.poll * 1000); |
| 573 | } |
| 574 | })(); |
| 575 | } else { |
| 576 | $scope.$watch(function () { |
| 577 | return _this.config.data; |
| 578 | }, function (data) { |
| 579 | if (data) { |
| 580 | prepareData(_this.config.data); |
| 581 | } |
| 582 | }, true); |
| 583 | } |
| 584 | |
| 585 | $scope.$on('create', function (event, chart) { |
| 586 | console.log('create: ' + chart.id); |
| 587 | }); |
| 588 | |
| 589 | $scope.$on('destroy', function (event, chart) { |
| 590 | console.log('destroy: ' + chart.id); |
| 591 | }); |
| 592 | }] |
| 593 | }); |
| 594 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 595 | //# sourceMappingURL=../../../maps/ui_components/smartComponents/smartPie/smartPie.component.js.map |
| 596 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 597 | 'use strict'; |
| 598 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 599 | /** |
| 600 | * © OpenCORD |
| 601 | * |
| 602 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 603 | * |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 604 | * Created by teone on 3/24/16. |
| 605 | */ |
| 606 | |
| 607 | (function () { |
| 608 | 'use strict'; |
| 609 | |
| 610 | angular.module('xos.uiComponents') |
| 611 | |
| 612 | /** |
| 613 | * @ngdoc directive |
| 614 | * @name xos.uiComponents.directive:xosTable |
| 615 | * @restrict E |
| 616 | * @description The xos-table directive |
| 617 | * @param {Object} config The configuration for the component. |
| 618 | * ``` |
| 619 | * { |
| 620 | * columns: [ |
| 621 | * { |
| 622 | * label: 'Human readable name', |
| 623 | * prop: 'Property to read in the model object', |
| 624 | * type: 'boolean'| 'array'| 'object'| 'custom'| 'date' | 'icon' // see examples for more details |
| 625 | formatter: fn(), // receive the whole item if tipe is custom and return a string |
| 626 | link: fn() // receive the whole item and return an url |
| 627 | * } |
| 628 | * ], |
| 629 | * classes: 'table table-striped table-bordered', |
| 630 | * actions: [ // if defined add an action column |
| 631 | { |
| 632 | label: 'delete', |
| 633 | icon: 'remove', // refers to bootstraps glyphicon |
| 634 | cb: (user) => { // receive the model |
| 635 | console.log(user); |
| 636 | }, |
| 637 | color: 'red' |
| 638 | } |
| 639 | ], |
| 640 | filter: 'field', // can be by `field` or `fulltext` |
| 641 | order: true | {field: 'property name', reverse: true | false} // whether to show ordering arrows, or a configuration for a default ordering |
| 642 | * } |
| 643 | * ``` |
| 644 | * @param {Array} data The data that should be rendered |
| 645 | * @element ANY |
| 646 | * @scope |
| 647 | * @example |
| 648 | # Basic usage |
| 649 | <example module="sampleTable1"> |
| 650 | <file name="index.html"> |
| 651 | <div ng-controller="SampleCtrl1 as vm"> |
| 652 | <xos-table data="vm.data" config="vm.config"></xos-table> |
| 653 | </div> |
| 654 | </file> |
| 655 | <file name="script.js"> |
| 656 | angular.module('sampleTable1', ['xos.uiComponents']) |
| 657 | .factory('_', function($window){ |
| 658 | return $window._; |
| 659 | }) |
| 660 | .controller('SampleCtrl1', function(){ |
| 661 | this.config = { |
| 662 | columns: [ |
| 663 | { |
| 664 | label: 'First Name', // column title |
| 665 | prop: 'name' // property to read in the data array |
| 666 | }, |
| 667 | { |
| 668 | label: 'Last Name', |
| 669 | prop: 'lastname' |
| 670 | } |
| 671 | ] |
| 672 | }; |
| 673 | this.data = [ |
| 674 | { |
| 675 | name: 'John', |
| 676 | lastname: 'Doe' |
| 677 | }, |
| 678 | { |
| 679 | name: 'Gili', |
| 680 | lastname: 'Fereydoun' |
| 681 | } |
| 682 | ] |
| 683 | }); |
| 684 | </file> |
| 685 | </example> |
| 686 | # Filtering |
| 687 | <example module="sampleTable2" animations="true"> |
| 688 | <file name="index.html"> |
| 689 | <div ng-controller="SampleCtrl2 as vm"> |
| 690 | <xos-table data="vm.data" config="vm.config"></xos-table> |
| 691 | </div> |
| 692 | </file> |
| 693 | <file name="script.js"> |
| 694 | angular.module('sampleTable2', ['xos.uiComponents', 'ngAnimate']) |
| 695 | .factory('_', function($window){ |
| 696 | return $window._; |
| 697 | }) |
| 698 | .controller('SampleCtrl2', function(){ |
| 699 | this.config = { |
| 700 | columns: [ |
| 701 | { |
| 702 | label: 'First Name', // column title |
| 703 | prop: 'name' // property to read in the data array |
| 704 | }, |
| 705 | { |
| 706 | label: 'Last Name', |
| 707 | prop: 'lastname' |
| 708 | } |
| 709 | ], |
| 710 | classes: 'table table-striped table-condensed', // table classes, default to `table table-striped table-bordered` |
| 711 | actions: [ // if defined add an action column |
| 712 | { |
| 713 | label: 'delete', // label |
| 714 | icon: 'remove', // icons, refers to bootstraps glyphicon |
| 715 | cb: (user) => { // callback, get feeded with the full object |
| 716 | console.log(user); |
| 717 | }, |
| 718 | color: 'red' // icon color |
| 719 | } |
| 720 | ], |
| 721 | filter: 'field', // can be by `field` or `fulltext` |
| 722 | order: true |
| 723 | }; |
| 724 | this.data = [ |
| 725 | { |
| 726 | name: 'John', |
| 727 | lastname: 'Doe' |
| 728 | }, |
| 729 | { |
| 730 | name: 'Gili', |
| 731 | lastname: 'Fereydoun' |
| 732 | } |
| 733 | ] |
| 734 | }); |
| 735 | </file> |
| 736 | </example> |
| 737 | # Pagination |
| 738 | <example module="sampleTable3"> |
| 739 | <file name="index.html"> |
| 740 | <div ng-controller="SampleCtrl3 as vm"> |
| 741 | <xos-table data="vm.data" config="vm.config"></xos-table> |
| 742 | </div> |
| 743 | </file> |
| 744 | <file name="script.js"> |
| 745 | angular.module('sampleTable3', ['xos.uiComponents']) |
| 746 | .factory('_', function($window){ |
| 747 | return $window._; |
| 748 | }) |
| 749 | .controller('SampleCtrl3', function(){ |
| 750 | this.config = { |
| 751 | columns: [ |
| 752 | { |
| 753 | label: 'First Name', // column title |
| 754 | prop: 'name' // property to read in the data array |
| 755 | }, |
| 756 | { |
| 757 | label: 'Last Name', |
| 758 | prop: 'lastname' |
| 759 | } |
| 760 | ], |
| 761 | pagination: { |
| 762 | pageSize: 2 |
| 763 | } |
| 764 | }; |
| 765 | this.data = [ |
| 766 | { |
| 767 | name: 'John', |
| 768 | lastname: 'Doe' |
| 769 | }, |
| 770 | { |
| 771 | name: 'Gili', |
| 772 | lastname: 'Fereydoun' |
| 773 | }, |
| 774 | { |
| 775 | name: 'Lucky', |
| 776 | lastname: 'Clarkson' |
| 777 | }, |
| 778 | { |
| 779 | name: 'Tate', |
| 780 | lastname: 'Spalding' |
| 781 | } |
| 782 | ] |
| 783 | }); |
| 784 | </file> |
| 785 | </example> |
| 786 | # Field formatter |
| 787 | <example module="sampleTable4"> |
| 788 | <file name="index.html"> |
| 789 | <div ng-controller="SampleCtrl as vm"> |
| 790 | <xos-table data="vm.data" config="vm.config"></xos-table> |
| 791 | </div> |
| 792 | </file> |
| 793 | <file name="script.js"> |
| 794 | angular.module('sampleTable4', ['xos.uiComponents']) |
| 795 | .factory('_', function($window){ |
| 796 | return $window._; |
| 797 | }) |
| 798 | .controller('SampleCtrl', function(){ |
| 799 | this.config = { |
| 800 | columns: [ |
| 801 | { |
| 802 | label: 'First Name', |
| 803 | prop: 'name', |
| 804 | link: item => `https://www.google.it/#q=${item.name}` |
| 805 | }, |
| 806 | { |
| 807 | label: 'Enabled', |
| 808 | prop: 'enabled', |
| 809 | type: 'boolean' |
| 810 | }, |
| 811 | { |
| 812 | label: 'Services', |
| 813 | prop: 'services', |
| 814 | type: 'array' |
| 815 | }, |
| 816 | { |
| 817 | label: 'Details', |
| 818 | prop: 'details', |
| 819 | type: 'object' |
| 820 | }, |
| 821 | { |
| 822 | label: 'Created', |
| 823 | prop: 'created', |
| 824 | type: 'date' |
| 825 | }, |
| 826 | { |
| 827 | label: 'Icon', |
| 828 | type: 'icon', |
| 829 | formatter: item => item.icon //note that this refer to [Bootstrap Glyphicon](http://getbootstrap.com/components/#glyphicons) |
| 830 | } |
| 831 | ] |
| 832 | }; |
| 833 | this.data = [ |
| 834 | { |
| 835 | name: 'John', |
| 836 | enabled: true, |
| 837 | services: ['Cdn', 'IpTv'], |
| 838 | details: { |
| 839 | c_tag: '243', |
| 840 | s_tag: '444' |
| 841 | }, |
| 842 | created: new Date('December 17, 1995 03:24:00'), |
| 843 | icon: 'music' |
| 844 | }, |
| 845 | { |
| 846 | name: 'Gili', |
| 847 | enabled: false, |
| 848 | services: ['Cdn', 'IpTv', 'Cache'], |
| 849 | details: { |
| 850 | c_tag: '675', |
| 851 | s_tag: '893' |
| 852 | }, |
| 853 | created: new Date(), |
| 854 | icon: 'camera' |
| 855 | } |
| 856 | ] |
| 857 | }); |
| 858 | </file> |
| 859 | </example> |
| 860 | # Custom formatter |
| 861 | <example module="sampleTable5"> |
| 862 | <file name="index.html"> |
| 863 | <div ng-controller="SampleCtrl as vm"> |
| 864 | <xos-table data="vm.data" config="vm.config"></xos-table> |
| 865 | </div> |
| 866 | </file> |
| 867 | <file name="script.js"> |
| 868 | angular.module('sampleTable5', ['xos.uiComponents']) |
| 869 | .factory('_', function($window){ |
| 870 | return $window._; |
| 871 | }) |
| 872 | .controller('SampleCtrl', function(){ |
| 873 | this.config = { |
| 874 | columns: [ |
| 875 | { |
| 876 | label: 'Username', |
| 877 | prop: 'username' |
| 878 | }, |
| 879 | { |
| 880 | label: 'Features', |
| 881 | type: 'custom', |
| 882 | formatter: (val) => { |
| 883 | |
| 884 | let cdnEnabled = val.features.cdn ? 'enabled' : 'disabled'; |
| 885 | return ` |
| 886 | Cdn is ${cdnEnabled}, |
| 887 | uplink speed is ${val.features.uplink_speed} |
| 888 | and downlink speed is ${val.features.downlink_speed} |
| 889 | `; |
| 890 | } |
| 891 | } |
| 892 | ] |
| 893 | }; |
| 894 | this.data = [ |
| 895 | { |
| 896 | username: 'John', |
| 897 | features: { |
| 898 | "cdn": false, |
| 899 | "uplink_speed": 1000000000, |
| 900 | "downlink_speed": 1000000000, |
| 901 | "uverse": true, |
| 902 | "status": "enabled" |
| 903 | } |
| 904 | }, |
| 905 | { |
| 906 | username: 'Gili', |
| 907 | features: { |
| 908 | "cdn": true, |
| 909 | "uplink_speed": 3000000000, |
| 910 | "downlink_speed": 2000000000, |
| 911 | "uverse": true, |
| 912 | "status": "enabled" |
| 913 | } |
| 914 | } |
| 915 | ] |
| 916 | }); |
| 917 | </file> |
| 918 | </example> |
| 919 | **/ |
| 920 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 921 | .component('xosTable', { |
| 922 | restrict: 'E', |
| 923 | bindings: { |
| 924 | data: '=', |
| 925 | config: '=' |
| 926 | }, |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 927 | template: '\n <div ng-show="vm.data.length > 0 && vm.loader == false">\n <div class="row" ng-if="vm.config.filter == \'fulltext\'">\n <div class="col-xs-12">\n <input\n class="form-control"\n placeholder="Type to search.."\n type="text"\n ng-model="vm.query"/>\n </div>\n </div>\n <table ng-class="vm.classes" ng-hide="vm.data.length == 0">\n <thead>\n <tr>\n <th ng-repeat="col in vm.columns">\n {{col.label}}\n <span ng-if="vm.config.order">\n <a href="" ng-click="vm.orderBy = col.prop; vm.reverse = false">\n <i class="glyphicon glyphicon-chevron-up"></i>\n </a>\n <a href="" ng-click="vm.orderBy = col.prop; vm.reverse = true">\n <i class="glyphicon glyphicon-chevron-down"></i>\n </a>\n </span>\n </th>\n <th ng-if="vm.config.actions">Actions:</th>\n </tr>\n </thead>\n <tbody ng-if="vm.config.filter == \'field\'">\n <tr>\n <td ng-repeat="col in vm.columns">\n <input\n ng-if="col.type !== \'boolean\' && col.type !== \'array\' && col.type !== \'object\' && col.type !== \'custom\'"\n class="form-control"\n placeholder="Type to search by {{col.label}}"\n type="text"\n ng-model="vm.query[col.prop]"/>\n <select\n ng-if="col.type === \'boolean\'"\n class="form-control"\n ng-model="vm.query[col.prop]">\n <option value="">-</option>\n <option value="true">True</option>\n <option value="false">False</option>\n </select>\n </td>\n <td ng-if="vm.config.actions"></td>\n </tr>\n </tbody>\n <tbody>\n <tr ng-repeat="item in vm.data | filter:vm.query:vm.comparator | orderBy:vm.orderBy:vm.reverse | pagination:vm.currentPage * vm.config.pagination.pageSize | limitTo: (vm.config.pagination.pageSize || vm.data.length) track by $index">\n <td ng-repeat="col in vm.columns" xos-link-wrapper>\n <span ng-if="!col.type || col.type === \'text\'">{{item[col.prop]}}</span>\n <span ng-if="col.type === \'boolean\'">\n <i class="glyphicon"\n ng-class="{\'glyphicon-ok\': item[col.prop], \'glyphicon-remove\': !item[col.prop]}">\n </i>\n </span>\n <span ng-if="col.type === \'date\'">\n {{item[col.prop] | date:\'H:mm MMM d, yyyy\'}}\n </span>\n <span ng-if="col.type === \'array\'">\n {{item[col.prop] | arrayToList}}\n </span>\n <span ng-if="col.type === \'object\'">\n <dl class="dl-horizontal">\n <span ng-repeat="(k,v) in item[col.prop]">\n <dt>{{k}}</dt>\n <dd>{{v}}</dd>\n </span>\n </dl>\n </span>\n <span ng-if="col.type === \'custom\'">\n {{col.formatter(item)}}\n </span>\n <span ng-if="col.type === \'icon\'">\n <i class="glyphicon glyphicon-{{col.formatter(item)}}">\n </i>\n </span>\n </td>\n <td ng-if="vm.config.actions">\n <a href=""\n ng-repeat="action in vm.config.actions"\n ng-click="action.cb(item)"\n title="{{action.label}}">\n <i\n class="glyphicon glyphicon-{{action.icon}}"\n style="color: {{action.color}};"></i>\n </a>\n </td>\n </tr>\n </tbody>\n </table>\n <xos-pagination\n ng-if="vm.config.pagination"\n page-size="vm.config.pagination.pageSize"\n total-elements="vm.data.length"\n change="vm.goToPage">\n </xos-pagination>\n </div>\n <div ng-show="(vm.data.length == 0 || !vm.data) && vm.loader == false">\n <xos-alert config="{type: \'info\'}">\n No data to show.\n </xos-alert>\n </div>\n <div ng-show="vm.loader == true">\n <div class="loader"></div>\n </div>\n ', |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 928 | bindToController: true, |
| 929 | controllerAs: 'vm', |
| 930 | controller: ["_", "$scope", "Comparator", function controller(_, $scope, Comparator) { |
| 931 | var _this = this; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 932 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 933 | this.comparator = Comparator; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 934 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 935 | this.loader = true; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 936 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 937 | $scope.$watch(function () { |
| 938 | return _this.data; |
| 939 | }, function (data) { |
| 940 | if (angular.isDefined(data)) { |
| 941 | _this.loader = false; |
| 942 | } |
| 943 | }); |
| 944 | |
| 945 | if (!this.config) { |
| 946 | throw new Error('[xosTable] Please provide a configuration via the "config" attribute'); |
| 947 | } |
| 948 | |
| 949 | if (!this.config.columns) { |
| 950 | throw new Error('[xosTable] Please provide a columns list in the configuration'); |
| 951 | } |
| 952 | |
| 953 | // handle default ordering |
| 954 | if (this.config.order && angular.isObject(this.config.order)) { |
| 955 | this.reverse = this.config.order.reverse || false; |
| 956 | this.orderBy = this.config.order.field || 'id'; |
| 957 | } |
| 958 | |
| 959 | // if columns with type 'custom' are provided |
| 960 | // check that a custom formatte3 is provided too |
| 961 | var customCols = _.filter(this.config.columns, { type: 'custom' }); |
| 962 | if (angular.isArray(customCols) && customCols.length > 0) { |
| 963 | _.forEach(customCols, function (col) { |
| 964 | if (!col.formatter || !angular.isFunction(col.formatter)) { |
| 965 | throw new Error('[xosTable] You have provided a custom field type, a formatter function should provided too.'); |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 966 | } |
| 967 | }); |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 968 | } |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 969 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 970 | // if columns with type 'icon' are provided |
| 971 | // check that a custom formatte3 is provided too |
| 972 | var iconCols = _.filter(this.config.columns, { type: 'icon' }); |
| 973 | if (angular.isArray(iconCols) && iconCols.length > 0) { |
| 974 | _.forEach(iconCols, function (col) { |
| 975 | if (!col.formatter || !angular.isFunction(col.formatter)) { |
| 976 | throw new Error('[xosTable] You have provided an icon field type, a formatter function should provided too.'); |
| 977 | } |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 978 | }); |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 979 | } |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 980 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 981 | // if a link property is passed, |
| 982 | // it should be a function |
| 983 | var linkedColumns = _.filter(this.config.columns, function (col) { |
| 984 | return angular.isDefined(col.link); |
| 985 | }); |
| 986 | if (angular.isArray(linkedColumns) && linkedColumns.length > 0) { |
| 987 | _.forEach(linkedColumns, function (col) { |
| 988 | if (!angular.isFunction(col.link)) { |
| 989 | throw new Error('[xosTable] The link property should be a function.'); |
| 990 | } |
| 991 | }); |
| 992 | } |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 993 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 994 | this.columns = this.config.columns; |
| 995 | this.classes = this.config.classes || 'table table-striped table-bordered'; |
| 996 | |
| 997 | if (this.config.actions) { |
| 998 | // TODO validate action format |
| 999 | } |
| 1000 | if (this.config.pagination) { |
| 1001 | this.currentPage = 0; |
| 1002 | this.goToPage = function (n) { |
| 1003 | _this.currentPage = n; |
| 1004 | }; |
| 1005 | } |
| 1006 | }] |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1007 | }) |
| 1008 | // TODO move in separate files |
| 1009 | // TODO test |
| 1010 | .filter('arrayToList', function () { |
| 1011 | return function (input) { |
| 1012 | if (!angular.isArray(input)) { |
| 1013 | return input; |
| 1014 | } |
| 1015 | return input.join(', '); |
| 1016 | }; |
| 1017 | }) |
| 1018 | // TODO test |
| 1019 | .directive('xosLinkWrapper', function () { |
| 1020 | return { |
| 1021 | restrict: 'A', |
| 1022 | transclude: true, |
| 1023 | template: '\n <a ng-if="col.link" href="{{col.link(item)}}">\n <div ng-transclude></div>\n </a>\n <div ng-transclude ng-if="!col.link"></div>\n ' |
| 1024 | }; |
| 1025 | }); |
| 1026 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 1027 | //# sourceMappingURL=../../../maps/ui_components/dumbComponents/table/table.component.js.map |
| 1028 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1029 | 'use strict'; |
| 1030 | |
| 1031 | /** |
| 1032 | * © OpenCORD |
| 1033 | * |
| 1034 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 1035 | * |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1036 | * Created by teone on 4/18/16. |
| 1037 | */ |
| 1038 | |
| 1039 | (function () { |
| 1040 | 'use strict'; |
| 1041 | |
| 1042 | angular.module('xos.uiComponents') |
| 1043 | |
| 1044 | /** |
| 1045 | * @ngdoc directive |
| 1046 | * @name xos.uiComponents.directive:xosForm |
| 1047 | * @restrict E |
| 1048 | * @description The xos-form directive. |
| 1049 | * This components have two usage, given a model it is able to autogenerate a form or it can be configured to create a custom form. |
| 1050 | * @param {Object} config The configuration object |
| 1051 | * ``` |
| 1052 | * { |
| 1053 | * exclude: ['id', 'validators', 'created', 'updated', 'deleted'], //field to be skipped in the form, the provide values are concatenated |
| 1054 | * actions: [ // define the form buttons with related callback |
| 1055 | * { |
| 1056 | label: 'save', |
| 1057 | icon: 'ok', // refers to bootstraps glyphicon |
| 1058 | cb: (user) => { // receive the model |
| 1059 | console.log(user); |
| 1060 | }, |
| 1061 | class: 'success' |
| 1062 | } |
| 1063 | * ], |
| 1064 | * feedback: { |
| 1065 | show: false, |
| 1066 | message: 'Form submitted successfully !!!', |
| 1067 | type: 'success' //refers to bootstrap class |
| 1068 | }, |
| 1069 | * fields: { |
| 1070 | * field_name: { |
| 1071 | * label: 'Field Label', |
| 1072 | * type: 'string' // options are: [date, boolean, number, email, string, select], |
| 1073 | * validators: { |
| 1074 | * minlength: number, |
| 1075 | maxlength: number, |
| 1076 | required: boolean, |
| 1077 | min: number, |
| 1078 | max: number, |
| 1079 | custom: (value) => { |
| 1080 | // do your validation here and return true | false |
| 1081 | // alternatively you can return an array [errorName, true|false] |
| 1082 | } |
| 1083 | * } |
| 1084 | * } |
| 1085 | * } |
| 1086 | * } |
| 1087 | * ``` |
| 1088 | * @element ANY |
| 1089 | * @scope |
| 1090 | * @requires xos.uiComponents.directive:xosField |
| 1091 | * @requires xos.uiComponents.XosFormHelpers |
| 1092 | * @requires xos.helpers._ |
| 1093 | * @example |
| 1094 | |
| 1095 | Autogenerated form |
| 1096 | <example module="sampleForm"> |
| 1097 | <file name="script.js"> |
| 1098 | angular.module('sampleForm', ['xos.uiComponents']) |
| 1099 | .factory('_', function($window){ |
| 1100 | return $window._; |
| 1101 | }) |
| 1102 | .controller('SampleCtrl', function(){ |
| 1103 | this.model = { |
| 1104 | first_name: 'Jhon', |
| 1105 | last_name: 'Doe', |
| 1106 | email: 'jhon.doe@sample.com', |
| 1107 | active: true, |
| 1108 | birthDate: '2015-02-17T22:06:38.059000Z' |
| 1109 | } |
| 1110 | this.config = { |
| 1111 | exclude: ['password', 'last_login'], |
| 1112 | formName: 'sampleForm', |
| 1113 | actions: [ |
| 1114 | { |
| 1115 | label: 'Save', |
| 1116 | icon: 'ok', // refers to bootstraps glyphicon |
| 1117 | cb: (user) => { // receive the model |
| 1118 | console.log(user); |
| 1119 | }, |
| 1120 | class: 'success' |
| 1121 | } |
| 1122 | ] |
| 1123 | }; |
| 1124 | }); |
| 1125 | </file> |
| 1126 | <file name="index.html"> |
| 1127 | <div ng-controller="SampleCtrl as vm"> |
| 1128 | <xos-form ng-model="vm.model" config="vm.config"></xos-form> |
| 1129 | </div> |
| 1130 | </file> |
| 1131 | </example> |
| 1132 | Configuration defined form |
| 1133 | <example module="sampleForm1"> |
| 1134 | <file name="script.js"> |
| 1135 | angular.module('sampleForm1', ['xos.uiComponents','ngResource', 'ngMockE2E']) |
| 1136 | .factory('_', function($window){ |
| 1137 | return $window._; |
| 1138 | }) |
| 1139 | .controller('SampleCtrl1', function(SampleResource){ |
| 1140 | this.model = { |
| 1141 | }; |
| 1142 | this.config = { |
| 1143 | exclude: ['password', 'last_login'], |
| 1144 | formName: 'sampleForm1', |
| 1145 | feedback: { |
| 1146 | show: false, |
| 1147 | message: 'Form submitted successfully !!!', |
| 1148 | type: 'success' |
| 1149 | }, |
| 1150 | actions: [ |
| 1151 | { |
| 1152 | label: 'Save', |
| 1153 | icon: 'ok', // refers to bootstraps glyphicon |
| 1154 | cb: (user) => { // receive the model |
| 1155 | console.log(user); |
| 1156 | this.config.feedback.show = true; |
| 1157 | this.config.feedback.type='success'; |
| 1158 | }, |
| 1159 | class: 'success' |
| 1160 | } |
| 1161 | ], |
| 1162 | fields: { |
| 1163 | first_name: { |
| 1164 | type: 'string', |
| 1165 | validators: { |
| 1166 | required: true |
| 1167 | } |
| 1168 | }, |
| 1169 | last_name: { |
| 1170 | label: 'Surname', |
| 1171 | type: 'string', |
| 1172 | validators: { |
| 1173 | required: true, |
| 1174 | minlength: 10 |
| 1175 | } |
| 1176 | }, |
| 1177 | age: { |
| 1178 | type: 'number', |
| 1179 | validators: { |
| 1180 | required: true, |
| 1181 | min: 21 |
| 1182 | } |
| 1183 | }, |
| 1184 | site: { |
| 1185 | label: 'Site', |
| 1186 | type: 'select', |
| 1187 | validators: { required: true}, |
| 1188 | hint: 'The Site this Slice belongs to', |
| 1189 | options: [] |
| 1190 | }, |
| 1191 | } |
| 1192 | }; |
| 1193 | SampleResource.query().$promise |
| 1194 | .then((users) => { |
| 1195 | //this.users_site = users; |
| 1196 | //console.log(users); |
| 1197 | this.optionVal = users; |
| 1198 | this.config.fields['site'].options = this.optionVal; |
| 1199 | //= this.optionVal; |
| 1200 | }) |
| 1201 | .catch((e) => { |
| 1202 | throw new Error(e); |
| 1203 | }); |
| 1204 | }); |
| 1205 | </file> |
| 1206 | <file name="backend.js"> |
| 1207 | angular.module('sampleForm1') |
| 1208 | .run(function($httpBackend, _){ |
| 1209 | let datas = [{id: 1, label: 'site1'},{id: 4, label: 'site4'},{id: 3, label: 'site3'}]; |
| 1210 | let paramsUrl = new RegExp(/\/test\/(.+)/); |
| 1211 | $httpBackend.whenGET('/test').respond(200, datas) |
| 1212 | }) |
| 1213 | .service('SampleResource', function($resource){ |
| 1214 | return $resource('/test/:id', {id: '@id'}); |
| 1215 | }); |
| 1216 | </file> |
| 1217 | <file name="index.html"> |
| 1218 | <div ng-controller="SampleCtrl1 as vm"> |
| 1219 | <xos-form ng-model="vm.model" config="vm.config"></xos-form> |
| 1220 | </div> |
| 1221 | </file> |
| 1222 | </example> |
| 1223 | **/ |
| 1224 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1225 | .component('xosForm', { |
| 1226 | restrict: 'E', |
| 1227 | bindings: { |
| 1228 | config: '=', |
| 1229 | ngModel: '=' |
| 1230 | }, |
| 1231 | template: '\n <form name="vm.{{vm.config.formName || \'form\'}}" novalidate>\n <div class="form-group" ng-repeat="(name, field) in vm.formField">\n <xos-field name="name" field="field" ng-model="vm.ngModel[name]"></xos-field>\n <xos-validation field="vm[vm.config.formName || \'form\'][name]" form = "vm[vm.config.formName || \'form\']"></xos-validation>\n <div class="alert alert-info" ng-show="(field.hint).length >0" role="alert">{{field.hint}}</div>\n </div>\n <div class="form-group" ng-if="vm.config.actions">\n <xos-alert config="vm.config.feedback" show="vm.config.feedback.show">{{vm.config.feedback.message}}</xos-alert>\n\n <button role="button" href=""\n ng-repeat="action in vm.config.actions"\n ng-click="action.cb(vm.ngModel, vm[vm.config.formName || \'form\'])"\n class="btn btn-{{action.class}}"\n title="{{action.label}}">\n <i class="glyphicon glyphicon-{{action.icon}}"></i>\n {{action.label}}\n </button>\n </div>\n </form>\n ', |
| 1232 | bindToController: true, |
| 1233 | controllerAs: 'vm', |
| 1234 | controller: ["$scope", "$log", "_", "XosFormHelpers", function controller($scope, $log, _, XosFormHelpers) { |
| 1235 | var _this = this; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1236 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1237 | if (!this.config) { |
| 1238 | throw new Error('[xosForm] Please provide a configuration via the "config" attribute'); |
| 1239 | } |
| 1240 | |
| 1241 | if (!this.config.actions) { |
| 1242 | throw new Error('[xosForm] Please provide an action list in the configuration'); |
| 1243 | } |
| 1244 | |
| 1245 | if (!this.config.feedback) { |
| 1246 | this.config.feedback = { |
| 1247 | show: false, |
| 1248 | message: 'Form submitted successfully !!!', |
| 1249 | type: 'success' |
| 1250 | }; |
| 1251 | } |
| 1252 | |
| 1253 | this.excludedField = ['id', 'validators', 'created', 'updated', 'deleted', 'backend_status']; |
| 1254 | if (this.config && this.config.exclude) { |
| 1255 | this.excludedField = this.excludedField.concat(this.config.exclude); |
| 1256 | } |
| 1257 | |
| 1258 | this.formField = []; |
| 1259 | |
| 1260 | $scope.$watch(function () { |
| 1261 | return _this.config; |
| 1262 | }, function () { |
| 1263 | if (!_this.ngModel) { |
| 1264 | return; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1265 | } |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1266 | var diff = _.difference(Object.keys(_this.ngModel), _this.excludedField); |
| 1267 | var modelField = XosFormHelpers.parseModelField(diff); |
| 1268 | _this.formField = XosFormHelpers.buildFormStructure(modelField, _this.config.fields, _this.ngModel); |
| 1269 | }, true); |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1270 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1271 | $scope.$watch(function () { |
| 1272 | return _this.ngModel; |
| 1273 | }, function (model) { |
| 1274 | // empty from old stuff |
| 1275 | _this.formField = {}; |
| 1276 | if (!model) { |
| 1277 | return; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1278 | } |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1279 | var diff = _.difference(Object.keys(model), _this.excludedField); |
| 1280 | var modelField = XosFormHelpers.parseModelField(diff); |
| 1281 | _this.formField = XosFormHelpers.buildFormStructure(modelField, _this.config.fields, model); |
| 1282 | }); |
| 1283 | }] |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1284 | }); |
| 1285 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 1286 | //# sourceMappingURL=../../../maps/ui_components/dumbComponents/form/form.component.js.map |
| 1287 | |
| 1288 | 'use strict'; |
| 1289 | |
| 1290 | /** |
| 1291 | * © OpenCORD |
| 1292 | * |
| 1293 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 1294 | * |
| 1295 | * Created by teone on 4/15/16. |
| 1296 | */ |
| 1297 | |
| 1298 | (function () { |
| 1299 | 'use strict'; |
| 1300 | |
| 1301 | angular.module('xos.uiComponents') |
| 1302 | |
| 1303 | /** |
| 1304 | * @ngdoc directive |
| 1305 | * @name xos.uiComponents.directive:xosPagination |
| 1306 | * @restrict E |
| 1307 | * @description The xos-table directive |
| 1308 | * @param {Number} pageSize Number of elements per page |
| 1309 | * @param {Number} totalElements Number of total elements in the collection |
| 1310 | * @param {Function} change The callback to be triggered on page change. |
| 1311 | * * @element ANY |
| 1312 | * @scope |
| 1313 | * @example |
| 1314 | <example module="samplePagination"> |
| 1315 | <file name="index.html"> |
| 1316 | <div ng-controller="SampleCtrl1 as vm"> |
| 1317 | <xos-pagination |
| 1318 | page-size="vm.pageSize" |
| 1319 | total-elements="vm.totalElements" |
| 1320 | change="vm.change"> |
| 1321 | </xos-pagination> |
| 1322 | </div> |
| 1323 | </file> |
| 1324 | <file name="script.js"> |
| 1325 | angular.module('samplePagination', ['xos.uiComponents']) |
| 1326 | .controller('SampleCtrl1', function(){ |
| 1327 | this.pageSize = 10; |
| 1328 | this.totalElements = 35; |
| 1329 | this.change = (pageNumber) => { |
| 1330 | console.log(pageNumber); |
| 1331 | } |
| 1332 | }); |
| 1333 | </file> |
| 1334 | </example> |
| 1335 | **/ |
| 1336 | |
| 1337 | .component('xosPagination', { |
| 1338 | restrict: 'E', |
| 1339 | bindings: { |
| 1340 | pageSize: '=', |
| 1341 | totalElements: '=', |
| 1342 | change: '=' |
| 1343 | }, |
| 1344 | template: '\n <div class="row" ng-if="vm.pageList.length > 1">\n <div class="col-xs-12 text-center">\n <ul class="pagination">\n <li\n ng-click="vm.goToPage(vm.currentPage - 1)"\n ng-class="{disabled: vm.currentPage == 0}">\n <a href="" aria-label="Previous">\n <span aria-hidden="true">«</span>\n </a>\n </li>\n <li ng-repeat="i in vm.pageList" ng-class="{active: i === vm.currentPage}">\n <a href="" ng-click="vm.goToPage(i)">{{i + 1}}</a>\n </li>\n <li\n ng-click="vm.goToPage(vm.currentPage + 1)"\n ng-class="{disabled: vm.currentPage == vm.pages - 1}">\n <a href="" aria-label="Next">\n <span aria-hidden="true">»</span>\n </a>\n </li>\n </ul>\n </div>\n </div>\n ', |
| 1345 | bindToController: true, |
| 1346 | controllerAs: 'vm', |
| 1347 | controller: ["$scope", function controller($scope) { |
| 1348 | var _this = this; |
| 1349 | |
| 1350 | this.currentPage = 0; |
| 1351 | |
| 1352 | this.goToPage = function (n) { |
| 1353 | if (n < 0 || n === _this.pages) { |
| 1354 | return; |
| 1355 | } |
| 1356 | _this.currentPage = n; |
| 1357 | _this.change(n); |
| 1358 | }; |
| 1359 | |
| 1360 | this.createPages = function (pages) { |
| 1361 | var arr = []; |
| 1362 | for (var i = 0; i < pages; i++) { |
| 1363 | arr.push(i); |
| 1364 | } |
| 1365 | return arr; |
| 1366 | }; |
| 1367 | |
| 1368 | // watch for data changes |
| 1369 | $scope.$watch(function () { |
| 1370 | return _this.totalElements; |
| 1371 | }, function () { |
| 1372 | if (_this.totalElements) { |
| 1373 | _this.pages = Math.ceil(_this.totalElements / _this.pageSize); |
| 1374 | _this.pageList = _this.createPages(_this.pages); |
| 1375 | } |
| 1376 | }); |
| 1377 | }] |
| 1378 | }).filter('pagination', function () { |
| 1379 | return function (input, start) { |
| 1380 | if (!input || !angular.isArray(input)) { |
| 1381 | return input; |
| 1382 | } |
| 1383 | start = parseInt(start, 10); |
| 1384 | return input.slice(start); |
| 1385 | }; |
| 1386 | }); |
| 1387 | })(); |
| 1388 | //# sourceMappingURL=../../../maps/ui_components/dumbComponents/pagination/pagination.component.js.map |
| 1389 | |
| 1390 | 'use strict'; |
| 1391 | |
| 1392 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } |
| 1393 | |
| 1394 | /** |
| 1395 | * © OpenCORD |
| 1396 | * |
| 1397 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 1398 | * |
| 1399 | * Created by teone on 5/25/16. |
| 1400 | */ |
| 1401 | |
| 1402 | (function () { |
| 1403 | 'use strict'; |
| 1404 | |
| 1405 | angular.module('xos.uiComponents') |
| 1406 | /** |
| 1407 | * @ngdoc directive |
| 1408 | * @name xos.uiComponents.directive:xosField |
| 1409 | * @restrict E |
| 1410 | * @description The xos-field directive. |
| 1411 | * This component decide, give a field wich kind of input it need to print. |
| 1412 | * @param {string} name The field name |
| 1413 | * @param {object} field The field configuration: |
| 1414 | * ``` |
| 1415 | * { |
| 1416 | * label: 'Label', |
| 1417 | * type: 'number', //typeof field |
| 1418 | * validators: {} // see xosForm for more details |
| 1419 | * } |
| 1420 | * ``` |
| 1421 | * @param {mixed} ngModel The field value |
| 1422 | * |
| 1423 | * @example |
| 1424 | |
| 1425 | # Basic Example |
| 1426 | |
| 1427 | <example module="sampleField1"> |
| 1428 | <file name="script.js"> |
| 1429 | angular.module('sampleField1', ['xos.uiComponents']) |
| 1430 | .factory('_', function($window){ |
| 1431 | return $window._; |
| 1432 | }) |
| 1433 | .controller('SampleCtrl', function(){ |
| 1434 | this.name = 'input-name'; |
| 1435 | this.field = {label: 'My String Value:', type: 'string'}; |
| 1436 | this.model = 'my string'; |
| 1437 | }); |
| 1438 | </file> |
| 1439 | <file name="index.html"> |
| 1440 | <div ng-controller="SampleCtrl as vm"> |
| 1441 | <xos-field ng-model="vm.model" name="vm.name" field="vm.field"></xos-field> |
| 1442 | </div> |
| 1443 | </file> |
| 1444 | </example> |
| 1445 | |
| 1446 | # Possible Values |
| 1447 | <example module="sampleField2"> |
| 1448 | <file name="script.js"> |
| 1449 | angular.module('sampleField2', ['xos.uiComponents']) |
| 1450 | .factory('_', function($window){ |
| 1451 | return $window._; |
| 1452 | }) |
| 1453 | .controller('SampleCtrl', function(){ |
| 1454 | this.field1 = { |
| 1455 | name: 'number-field', |
| 1456 | field: {label: 'My Number Value:', type: 'number'}, |
| 1457 | model: 2 |
| 1458 | }; |
| 1459 | this.field2 = { |
| 1460 | name: 'date-field', |
| 1461 | field: {label: 'My Date Value:', type: 'date'}, |
| 1462 | model: new Date() |
| 1463 | }; |
| 1464 | this.field3 = { |
| 1465 | name: 'boolean-field', |
| 1466 | field: {label: 'My Boolean Value:', type: 'boolean'}, |
| 1467 | model: true |
| 1468 | }; |
| 1469 | this.field4 = { |
| 1470 | name: 'email-field', |
| 1471 | field: {label: 'My Email Value:', type: 'email'}, |
| 1472 | model: 'sample@domain.us' |
| 1473 | }; |
| 1474 | }); |
| 1475 | </file> |
| 1476 | <file name="index.html"> |
| 1477 | <div ng-controller="SampleCtrl as vm"> |
| 1478 | <xos-field ng-model="vm.field1.model" name="vm.field1.name" field="vm.field1.field"></xos-field> |
| 1479 | <xos-field ng-model="vm.field2.model" name="vm.field2.name" field="vm.field2.field"></xos-field> |
| 1480 | <xos-field ng-model="vm.field3.model" name="vm.field3.name" field="vm.field3.field"></xos-field> |
| 1481 | <xos-field ng-model="vm.field4.model" name="vm.field4.name" field="vm.field4.field"></xos-field> |
| 1482 | </div> |
| 1483 | </file> |
| 1484 | </example> |
| 1485 | # This element is recursive |
| 1486 | <example module="sampleField3"> |
| 1487 | <file name="script.js"> |
| 1488 | angular.module('sampleField3', ['xos.uiComponents']) |
| 1489 | .factory('_', function($window){ |
| 1490 | return $window._; |
| 1491 | }) |
| 1492 | .controller('SampleCtrl', function(){ |
| 1493 | this.name1 = 'input-name'; |
| 1494 | this.field1 = {label: 'My Object Field:', type: 'object'}; |
| 1495 | this.model1 = { |
| 1496 | name: 'Jhon', |
| 1497 | age: '25', |
| 1498 | email: 'jhon@thewall.ru', |
| 1499 | active: true |
| 1500 | }; |
| 1501 | this.name2 = 'another-name'; |
| 1502 | this.field2 = { |
| 1503 | label: 'Empty Object Field', |
| 1504 | type: 'object', |
| 1505 | properties: { |
| 1506 | foo: { |
| 1507 | label: 'FooLabel:', |
| 1508 | type: 'string', |
| 1509 | validators: { |
| 1510 | required: true |
| 1511 | } |
| 1512 | }, |
| 1513 | bar: { |
| 1514 | type: 'number' |
| 1515 | } |
| 1516 | } |
| 1517 | } |
| 1518 | }); |
| 1519 | </file> |
| 1520 | <file name="index.html"> |
| 1521 | <div ng-controller="SampleCtrl as vm"> |
| 1522 | <h4>Autogenerated object field</h4> |
| 1523 | <xos-field ng-model="vm.model1" name="vm.name1" field="vm.field1"></xos-field> |
| 1524 | <h4>Configured object field</h4> |
| 1525 | <xos-field ng-model="vm.model2" name="vm.name2" field="vm.field2"></xos-field> |
| 1526 | </div> |
| 1527 | </file> |
| 1528 | </example> |
| 1529 | */ |
| 1530 | .component('xosField', { |
| 1531 | restrict: 'E', |
| 1532 | bindings: { |
| 1533 | name: '=', |
| 1534 | field: '=', |
| 1535 | ngModel: '=' |
| 1536 | }, |
| 1537 | template: '\n <label ng-if="vm.field.type !== \'object\'">{{vm.field.label}}</label>\n <input\n xos-custom-validator custom-validator="vm.field.validators.custom || null"\n ng-if="vm.field.type !== \'boolean\' && vm.field.type !== \'object\' && vm.field.type !== \'select\'"\n type="{{vm.field.type}}"\n name="{{vm.name}}"\n class="form-control"\n ng-model="vm.ngModel"\n ng-minlength="vm.field.validators.minlength || 0"\n ng-maxlength="vm.field.validators.maxlength || 2000"\n ng-required="vm.field.validators.required || false" />\n <select class="form-control" ng-if ="vm.field.type === \'select\'"\n name = "{{vm.name}}"\n ng-options="item.id as item.label for item in vm.field.options"\n ng-model="vm.ngModel"\n ng-required="vm.field.validators.required || false">\n </select>\n <span class="boolean-field" ng-if="vm.field.type === \'boolean\'">\n <a href="#"\n class="btn btn-success"\n ng-show="vm.ngModel"\n ng-click="vm.ngModel = false">\n <i class="glyphicon glyphicon-ok"></i>\n </a>\n <a href="#"\n class="btn btn-danger"\n ng-show="!vm.ngModel"\n ng-click="vm.ngModel = true">\n <i class="glyphicon glyphicon-remove"></i>\n </a>\n </span>\n <div\n class="panel panel-default object-field"\n ng-if="vm.field.type == \'object\' && (!vm.isEmptyObject(vm.ngModel) || !vm.isEmptyObject(vm.field.properties))"\n >\n <div class="panel-heading">{{vm.field.label}}</div>\n <div class="panel-body">\n <div ng-if="!vm.field.properties" ng-repeat="(k, v) in vm.ngModel">\n <xos-field\n name="k"\n field="{label: vm.formatLabel(k), type: vm.getType(v)}"\n ng-model="v">\n </xos-field>\n </div>\n <div ng-if="vm.field.properties" ng-repeat="(k, v) in vm.field.properties">\n <xos-field\n name="k"\n field="{\n label: v.label || vm.formatLabel(k),\n type: v.type,\n validators: v.validators\n }"\n ng-model="vm.ngModel[k]">\n </xos-field>\n </div>\n </div>\n </div>\n ', |
| 1538 | bindToController: true, |
| 1539 | controllerAs: 'vm', |
| 1540 | // the compile cicle is needed to support recursion |
| 1541 | //compile: function (element) { |
| 1542 | // return RecursionHelper.compile(element); |
| 1543 | //}, |
| 1544 | controller: ["$attrs", "XosFormHelpers", "LabelFormatter", function controller($attrs, XosFormHelpers, LabelFormatter) { |
| 1545 | |
| 1546 | if (!this.name) { |
| 1547 | throw new Error('[xosField] Please provide a field name'); |
| 1548 | } |
| 1549 | if (!this.field) { |
| 1550 | throw new Error('[xosField] Please provide a field definition'); |
| 1551 | } |
| 1552 | if (!this.field.type) { |
| 1553 | throw new Error('[xosField] Please provide a type in the field definition'); |
| 1554 | } |
| 1555 | if (!$attrs.ngModel) { |
| 1556 | throw new Error('[xosField] Please provide an ng-model'); |
| 1557 | } |
| 1558 | this.getType = XosFormHelpers._getFieldFormat; |
| 1559 | this.formatLabel = LabelFormatter.format; |
| 1560 | |
| 1561 | this.isEmptyObject = function (o) { |
| 1562 | return o ? Object.keys(o).length === 0 : true; |
| 1563 | }; |
| 1564 | }] |
| 1565 | }) |
| 1566 | |
| 1567 | /** |
| 1568 | * @ngdoc directive |
| 1569 | * @name xos.uiComponents.directive:xosCustomValidator |
| 1570 | * @restrict A |
| 1571 | * @description The xosCustomValidator directive. |
| 1572 | * This component apply a custom validation function |
| 1573 | * @param {function} customValidator The function that execute the validation. |
| 1574 | * |
| 1575 | * You should do your validation here and return true | false, |
| 1576 | * or alternatively you can return an array [errorName, true|false] |
| 1577 | */ |
| 1578 | .directive('xosCustomValidator', function () { |
| 1579 | return { |
| 1580 | restrict: 'A', |
| 1581 | scope: { |
| 1582 | fn: '=customValidator' |
| 1583 | }, |
| 1584 | require: 'ngModel', |
| 1585 | link: function link(scope, element, attr, ctrl) { |
| 1586 | if (!angular.isFunction(scope.fn)) { |
| 1587 | return; |
| 1588 | } |
| 1589 | |
| 1590 | function customValidatorWrapper(ngModelValue) { |
| 1591 | var valid = scope.fn(ngModelValue); |
| 1592 | if (angular.isArray(valid)) { |
| 1593 | // ES6 spread rocks over fn.apply() |
| 1594 | ctrl.$setValidity.apply(ctrl, _toConsumableArray(valid)); |
| 1595 | } else { |
| 1596 | ctrl.$setValidity('custom', valid); |
| 1597 | } |
| 1598 | return ngModelValue; |
| 1599 | } |
| 1600 | |
| 1601 | ctrl.$parsers.push(customValidatorWrapper); |
| 1602 | } |
| 1603 | }; |
| 1604 | }); |
| 1605 | })(); |
| 1606 | //# sourceMappingURL=../../../maps/ui_components/dumbComponents/field/field.component.js.map |
| 1607 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1608 | 'use strict'; |
| 1609 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1610 | /** |
| 1611 | * © OpenCORD |
| 1612 | * |
| 1613 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 1614 | * |
| 1615 | * Created by teone on 4/15/16. |
| 1616 | */ |
| 1617 | |
| 1618 | (function () { |
| 1619 | 'use strict'; |
| 1620 | |
| 1621 | angular.module('xos.uiComponents') |
| 1622 | |
| 1623 | /** |
| 1624 | * @ngdoc directive |
| 1625 | * @name xos.uiComponents.directive:xosAlert |
| 1626 | * @restrict E |
| 1627 | * @description The xos-alert directive |
| 1628 | * @param {Object} config The configuration object |
| 1629 | * ``` |
| 1630 | * { |
| 1631 | * type: 'danger', //info, success, warning |
| 1632 | * closeBtn: true, //default false |
| 1633 | * autoHide: 3000 //delay to automatically hide the alert |
| 1634 | * } |
| 1635 | * ``` |
| 1636 | * @param {Boolean=} show Binding to show and hide the alert, default to true |
| 1637 | * @element ANY |
| 1638 | * @scope |
| 1639 | * @example |
| 1640 | <example module="sampleAlert1"> |
| 1641 | <file name="index.html"> |
| 1642 | <div ng-controller="SampleCtrl1 as vm"> |
| 1643 | <xos-alert config="vm.config1"> |
| 1644 | A sample alert message |
| 1645 | </xos-alert> |
| 1646 | <xos-alert config="vm.config2"> |
| 1647 | A sample alert message (with close button) |
| 1648 | </xos-alert> |
| 1649 | <xos-alert config="vm.config3"> |
| 1650 | A sample info message |
| 1651 | </xos-alert> |
| 1652 | <xos-alert config="vm.config4"> |
| 1653 | A sample success message |
| 1654 | </xos-alert> |
| 1655 | <xos-alert config="vm.config5"> |
| 1656 | A sample warning message |
| 1657 | </xos-alert> |
| 1658 | </div> |
| 1659 | </file> |
| 1660 | <file name="script.js"> |
| 1661 | angular.module('sampleAlert1', ['xos.uiComponents']) |
| 1662 | .controller('SampleCtrl1', function(){ |
| 1663 | this.config1 = { |
| 1664 | type: 'danger' |
| 1665 | }; |
| 1666 | this.config2 = { |
| 1667 | type: 'danger', |
| 1668 | closeBtn: true |
| 1669 | }; |
| 1670 | this.config3 = { |
| 1671 | type: 'info' |
| 1672 | }; |
| 1673 | this.config4 = { |
| 1674 | type: 'success' |
| 1675 | }; |
| 1676 | this.config5 = { |
| 1677 | type: 'warning' |
| 1678 | }; |
| 1679 | }); |
| 1680 | </file> |
| 1681 | </example> |
| 1682 | <example module="sampleAlert2" animations="true"> |
| 1683 | <file name="index.html"> |
| 1684 | <div ng-controller="SampleCtrl as vm" class="row"> |
| 1685 | <div class="col-sm-4"> |
| 1686 | <a class="btn btn-default btn-block" ng-show="!vm.show" ng-click="vm.show = true">Show Alert</a> |
| 1687 | <a class="btn btn-default btn-block" ng-show="vm.show" ng-click="vm.show = false">Hide Alert</a> |
| 1688 | </div> |
| 1689 | <div class="col-sm-8"> |
| 1690 | <xos-alert config="vm.config1" show="vm.show"> |
| 1691 | A sample alert message, not displayed by default. |
| 1692 | </xos-alert> |
| 1693 | </div> |
| 1694 | </div> |
| 1695 | </file> |
| 1696 | <file name="script.js"> |
| 1697 | angular.module('sampleAlert2', ['xos.uiComponents', 'ngAnimate']) |
| 1698 | .controller('SampleCtrl', function(){ |
| 1699 | this.config1 = { |
| 1700 | type: 'success' |
| 1701 | }; |
| 1702 | this.show = false; |
| 1703 | }); |
| 1704 | </file> |
| 1705 | </example> |
| 1706 | **/ |
| 1707 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1708 | .component('xosAlert', { |
| 1709 | restrict: 'E', |
| 1710 | bindings: { |
| 1711 | config: '=', |
| 1712 | show: '=?' |
| 1713 | }, |
| 1714 | template: '\n <div ng-cloak class="alert alert-{{vm.config.type}}" ng-hide="!vm.show">\n <button type="button" class="close" ng-if="vm.config.closeBtn" ng-click="vm.dismiss()">\n <span aria-hidden="true">×</span>\n </button>\n <p ng-transclude></p>\n </div>\n ', |
| 1715 | transclude: true, |
| 1716 | bindToController: true, |
| 1717 | controllerAs: 'vm', |
| 1718 | controller: ["$timeout", function controller($timeout) { |
| 1719 | var _this = this; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1720 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1721 | if (!this.config) { |
| 1722 | throw new Error('[xosAlert] Please provide a configuration via the "config" attribute'); |
| 1723 | } |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1724 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1725 | // default the value to true |
| 1726 | this.show = this.show !== false; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1727 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1728 | this.dismiss = function () { |
| 1729 | _this.show = false; |
| 1730 | }; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1731 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1732 | if (this.config.autoHide) { |
| 1733 | (function () { |
| 1734 | var to = $timeout(function () { |
| 1735 | _this.dismiss(); |
| 1736 | $timeout.cancel(to); |
| 1737 | }, _this.config.autoHide); |
| 1738 | })(); |
| 1739 | } |
| 1740 | }] |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1741 | }); |
| 1742 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 1743 | //# sourceMappingURL=../../../maps/ui_components/dumbComponents/alert/alert.component.js.map |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1744 | |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 1745 | 'use strict'; |
| 1746 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1747 | (function () { |
| 1748 | 'use strict'; |
| 1749 | |
| 1750 | /** |
| 1751 | * @ngdoc service |
| 1752 | * @name xos.uiComponents.LabelFormatter |
| 1753 | * @description This factory define a set of helper function to format label started from an object property |
| 1754 | **/ |
| 1755 | |
| 1756 | angular.module('xos.uiComponents').factory('LabelFormatter', labelFormatter); |
| 1757 | |
| 1758 | function labelFormatter() { |
| 1759 | |
| 1760 | /** |
| 1761 | * @ngdoc method |
| 1762 | * @name xos.uiComponents.LabelFormatter#_formatByUnderscore |
| 1763 | * @methodOf xos.uiComponents.LabelFormatter |
| 1764 | * @description |
| 1765 | * Convert a `snake_case` string to readable string.<br/> |
| 1766 | * Eg: `this_string` will became `this string` |
| 1767 | * @param {string} string The string to be converted |
| 1768 | * @returns {string} The converten string |
| 1769 | **/ |
| 1770 | |
| 1771 | var _formatByUnderscore = function _formatByUnderscore(string) { |
| 1772 | return string.split('_').join(' ').trim(); |
| 1773 | }; |
| 1774 | |
| 1775 | /** |
| 1776 | * @ngdoc method |
| 1777 | * @name xos.uiComponents.LabelFormatter#_formatByUppercase |
| 1778 | * @methodOf xos.uiComponents.LabelFormatter |
| 1779 | * @description |
| 1780 | * Convert a `camelCase` string to readable string.<br/> |
| 1781 | * Eg: `thisString` will became `this string` |
| 1782 | * @param {string} string The string to be converted |
| 1783 | * @returns {string} The converten string |
| 1784 | **/ |
| 1785 | |
| 1786 | var _formatByUppercase = function _formatByUppercase(string) { |
| 1787 | return string.split(/(?=[A-Z])/).map(function (w) { |
| 1788 | return w.toLowerCase(); |
| 1789 | }).join(' '); |
| 1790 | }; |
| 1791 | |
| 1792 | /** |
| 1793 | * @ngdoc method |
| 1794 | * @name xos.uiComponents.LabelFormatter#_capitalize |
| 1795 | * @methodOf xos.uiComponents.LabelFormatter |
| 1796 | * @description |
| 1797 | * Capitalize the first letter of a string.<br/> |
| 1798 | * Eg: `this string` will became `This string` |
| 1799 | * @param {string} string The string to be converted |
| 1800 | * @returns {string} The converten string |
| 1801 | **/ |
| 1802 | |
| 1803 | var _capitalize = function _capitalize(string) { |
| 1804 | return string.slice(0, 1).toUpperCase() + string.slice(1); |
| 1805 | }; |
| 1806 | |
| 1807 | /** |
| 1808 | * @ngdoc method |
| 1809 | * @name xos.uiComponents.LabelFormatter#format |
| 1810 | * @methodOf xos.uiComponents.LabelFormatter |
| 1811 | * @description |
| 1812 | * Apply in order: |
| 1813 | * - _formatByUnderscore |
| 1814 | * - _formatByUppercase |
| 1815 | * - _capitalize |
| 1816 | * - replace multiple space with a single one |
| 1817 | * - append `:` at the end |
| 1818 | * <br/> |
| 1819 | * Eg: `this_string` will became `This string:`<br/> |
| 1820 | * Eg: `thisString` will became `This string:` |
| 1821 | * @param {string} string The string to be converted |
| 1822 | * @returns {string} The converten string |
| 1823 | **/ |
| 1824 | |
| 1825 | var format = function format(string) { |
| 1826 | string = _formatByUnderscore(string); |
| 1827 | string = _formatByUppercase(string); |
| 1828 | |
| 1829 | string = _capitalize(string).replace(/\s\s+/g, ' ') + ':'; |
| 1830 | return string.replace('::', ':'); |
| 1831 | }; |
| 1832 | |
| 1833 | return { |
| 1834 | // test export |
| 1835 | _formatByUnderscore: _formatByUnderscore, |
| 1836 | _formatByUppercase: _formatByUppercase, |
| 1837 | _capitalize: _capitalize, |
| 1838 | // export to use |
| 1839 | format: format |
| 1840 | }; |
| 1841 | } |
| 1842 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 1843 | //# sourceMappingURL=../../../maps/services/helpers/ui/label_formatter.service.js.map |
| 1844 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1845 | 'use strict'; |
| 1846 | |
| 1847 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; |
| 1848 | |
| 1849 | (function () { |
| 1850 | |
| 1851 | angular.module('xos.uiComponents') |
| 1852 | |
| 1853 | /** |
| 1854 | * @ngdoc service |
| 1855 | * @name xos.uiComponents.XosFormHelpers |
| 1856 | * @requires xos.uiComponents.LabelFormatter |
| 1857 | * @requires xos.helpers._ |
| 1858 | **/ |
| 1859 | |
| 1860 | .service('XosFormHelpers', ["_", "LabelFormatter", function (_, LabelFormatter) { |
| 1861 | var _this = this; |
| 1862 | |
| 1863 | /** |
| 1864 | * @ngdoc method |
| 1865 | * @name xos.uiComponents.XosFormHelpers#_isEmail |
| 1866 | * @methodOf xos.uiComponents.XosFormHelpers |
| 1867 | * @description |
| 1868 | * Return true if the string is an email address |
| 1869 | * @param {string} text The string to be evaluated |
| 1870 | * @returns {boolean} If the string match an email format |
| 1871 | **/ |
| 1872 | |
| 1873 | this._isEmail = function (text) { |
| 1874 | var re = /(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/; |
| 1875 | return re.test(text); |
| 1876 | }; |
| 1877 | |
| 1878 | /** |
| 1879 | * @ngdoc method |
| 1880 | * @name xos.uiComponents.XosFormHelpers#_getFieldFormat |
| 1881 | * @methodOf xos.uiComponents.XosFormHelpers |
| 1882 | * @description |
| 1883 | * Return the type of the input |
| 1884 | * @param {mixed} value The data to be evaluated |
| 1885 | * @returns {string} The type of the input |
| 1886 | **/ |
| 1887 | |
| 1888 | this._getFieldFormat = function (value) { |
| 1889 | |
| 1890 | if (angular.isArray(value)) { |
| 1891 | return 'array'; |
| 1892 | } |
| 1893 | |
| 1894 | // check if is date |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 1895 | if (angular.isDate(value) || !Number.isNaN(Date.parse(value)) && // Date.parse is a number |
| 1896 | /^\d+-\d+-\d+\D\d+:\d+:\d+\.\d+\D/.test(value) // the format match ISO dates |
| 1897 | ) { |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1898 | return 'date'; |
| 1899 | } |
| 1900 | |
| 1901 | // check if is boolean |
| 1902 | // isNaN(false) = false, false is a number (0), true is a number (1) |
| 1903 | if (typeof value === 'boolean') { |
| 1904 | return 'boolean'; |
| 1905 | } |
| 1906 | |
| 1907 | // check if a string is an email |
| 1908 | if (_this._isEmail(value)) { |
| 1909 | return 'email'; |
| 1910 | } |
| 1911 | |
| 1912 | // if null return string |
| 1913 | if (angular.isString(value) || value === null) { |
| 1914 | return 'text'; |
| 1915 | } |
| 1916 | |
| 1917 | return typeof value === 'undefined' ? 'undefined' : _typeof(value); |
| 1918 | }; |
| 1919 | |
| 1920 | /** |
| 1921 | * @ngdoc method |
| 1922 | * @name xos.uiComponents.XosFormHelpers#buildFormStructure |
| 1923 | * @methodOf xos.uiComponents.XosFormHelpers |
| 1924 | * @description |
| 1925 | * Return the type of the input |
| 1926 | * @param {object} modelField An object containing one property for each field of the model |
| 1927 | * @param {object} customField An object containing one property for each field custom field |
| 1928 | * @param {object} model The actual model on wich build the form structure (it is used to determine the type of the input) |
| 1929 | * @returns {object} An object describing the form structure in the form of: |
| 1930 | * ``` |
| 1931 | * { |
| 1932 | * 'field-name': { |
| 1933 | * label: 'Label', |
| 1934 | * type: 'number', //typeof field |
| 1935 | * validators: {}, // see xosForm for more details |
| 1936 | * hint: 'A Custom hint for the field' |
| 1937 | * } |
| 1938 | * } |
| 1939 | * ``` |
| 1940 | **/ |
| 1941 | |
| 1942 | this.buildFormStructure = function (modelField, customField, model) { |
| 1943 | |
| 1944 | modelField = angular.extend(modelField, customField); |
| 1945 | customField = customField || {}; |
| 1946 | |
| 1947 | return _.reduce(Object.keys(modelField), function (form, f) { |
| 1948 | |
| 1949 | form[f] = { |
| 1950 | label: customField[f] && customField[f].label ? customField[f].label + ':' : LabelFormatter.format(f), |
| 1951 | type: customField[f] && customField[f].type ? customField[f].type : _this._getFieldFormat(model[f]), |
| 1952 | validators: customField[f] && customField[f].validators ? customField[f].validators : {}, |
| 1953 | hint: customField[f] && customField[f].hint ? customField[f].hint : '' |
| 1954 | }; |
| 1955 | |
| 1956 | if (customField[f] && customField[f].options) { |
| 1957 | form[f].options = customField[f].options; |
| 1958 | } |
| 1959 | if (customField[f] && customField[f].properties) { |
| 1960 | form[f].properties = customField[f].properties; |
| 1961 | } |
| 1962 | if (form[f].type === 'date') { |
| 1963 | model[f] = new Date(model[f]); |
| 1964 | } |
| 1965 | |
| 1966 | if (form[f].type === 'number') { |
| 1967 | model[f] = parseInt(model[f], 10); |
| 1968 | } |
| 1969 | |
| 1970 | return form; |
| 1971 | }, {}); |
| 1972 | }; |
| 1973 | |
| 1974 | /** |
| 1975 | * @ngdoc method |
| 1976 | * @name xos.uiComponents.XosFormHelpers#parseModelField |
| 1977 | * @methodOf xos.uiComponents.XosFormHelpers |
| 1978 | * @description |
| 1979 | * Helpers for buildFormStructure, convert a list of model properties in an object used to build the form structure, eg: |
| 1980 | * ``` |
| 1981 | * // input: |
| 1982 | * ['id', 'name'm 'mail'] |
| 1983 | * |
| 1984 | * // output |
| 1985 | * { |
| 1986 | * id: {}, |
| 1987 | * name: {}, |
| 1988 | * mail: {} |
| 1989 | * } |
| 1990 | * ``` |
| 1991 | * @param {array} fields An array of fields representing the model properties |
| 1992 | * @returns {object} An object containing one property for each field of the model |
| 1993 | **/ |
| 1994 | |
| 1995 | this.parseModelField = function (fields) { |
| 1996 | return _.reduce(fields, function (form, f) { |
| 1997 | form[f] = {}; |
| 1998 | return form; |
| 1999 | }, {}); |
| 2000 | }; |
| 2001 | }]); |
| 2002 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2003 | //# sourceMappingURL=../../../maps/services/helpers/ui/form.helpers.js.map |
| 2004 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2005 | 'use strict'; |
| 2006 | |
| 2007 | (function () { |
| 2008 | 'use strict'; |
| 2009 | |
| 2010 | /** |
| 2011 | * @ngdoc service |
| 2012 | * @name xos.uiComponents.Comparator |
| 2013 | * @description |
| 2014 | * This factory define a function that replace the native angular.filter comparator. |
| 2015 | * |
| 2016 | * It is done to allow the comparation between (0|1) values with booleans. |
| 2017 | * >Note that this factory return a single function, not an object. |
| 2018 | * |
| 2019 | * The tipical usage of this factory is inside an `ng-repeat` |
| 2020 | * @example |
| 2021 | * <example module="comparator"> |
| 2022 | * <file name="index.html"> |
| 2023 | * <div ng-controller="sample as vm"> |
| 2024 | * <div class="row"> |
| 2025 | * <div class="col-xs-6"> |
| 2026 | * <label>Filter by name:</label> |
| 2027 | * <input class="form-control" type="text" ng-model="vm.query.name"/> |
| 2028 | * </div> |
| 2029 | * <div class="col-xs-6"> |
| 2030 | * <label>Filter by status:</label> |
| 2031 | * <select |
| 2032 | * ng-model="vm.query.status" |
| 2033 | * ng-options="i for i in [true, false]"> |
| 2034 | * </select> |
| 2035 | * </div> |
| 2036 | * </div> |
| 2037 | * <div ng-repeat="item in vm.data | filter:vm.query:vm.comparator"> |
| 2038 | * <div class="row"> |
| 2039 | * <div class="col-xs-6">{{item.name}}</div> |
| 2040 | * <div class="col-xs-6">{{item.status}}</div> |
| 2041 | * </div> |
| 2042 | * </div> |
| 2043 | * </div> |
| 2044 | * </file> |
| 2045 | * <file name="script.js"> |
| 2046 | * angular.module('comparator', ['xos.uiComponents']) |
| 2047 | * .controller('sample', function(Comparator){ |
| 2048 | * this.comparator = Comparator; |
| 2049 | * this.data = [ |
| 2050 | * {name: 'Jhon', status: 1}, |
| 2051 | * {name: 'Jack', status: 0}, |
| 2052 | * {name: 'Mike', status: 1}, |
| 2053 | * {name: 'Scott', status: 0} |
| 2054 | * ]; |
| 2055 | * }); |
| 2056 | * </file> |
| 2057 | * </example> |
| 2058 | **/ |
| 2059 | |
| 2060 | comparator.$inject = ["_"]; |
| 2061 | angular.module('xos.uiComponents').factory('Comparator', comparator); |
| 2062 | |
| 2063 | function comparator(_) { |
| 2064 | |
| 2065 | return function (actual, expected) { |
| 2066 | |
| 2067 | if (angular.isUndefined(actual)) { |
| 2068 | // No substring matching against `undefined` |
| 2069 | return false; |
| 2070 | } |
| 2071 | if (actual === null || expected === null) { |
| 2072 | // No substring matching against `null`; only match against `null` |
| 2073 | return actual === expected; |
| 2074 | } |
| 2075 | if (angular.isObject(expected) || angular.isObject(actual)) { |
| 2076 | return angular.equals(expected, actual); |
| 2077 | } |
| 2078 | |
| 2079 | if (_.isBoolean(actual) || _.isBoolean(expected)) { |
| 2080 | if (actual === 0 || actual === 1) { |
| 2081 | actual = !!actual; |
| 2082 | } |
| 2083 | return angular.equals(expected, actual); |
| 2084 | } |
| 2085 | |
| 2086 | if (!angular.isString(actual) || !angular.isString(expected)) { |
| 2087 | if (angular.isDefined(actual.toString) && angular.isDefined(expected.toString)) { |
| 2088 | actual = actual.toString(); |
| 2089 | expected = expected.toString(); |
| 2090 | } else { |
| 2091 | return actual === expected; |
| 2092 | } |
| 2093 | } |
| 2094 | |
| 2095 | actual = actual.toLowerCase() + ''; |
| 2096 | expected = expected.toLowerCase() + ''; |
| 2097 | return actual.indexOf(expected) !== -1; |
| 2098 | }; |
| 2099 | } |
| 2100 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2101 | //# sourceMappingURL=../../../maps/services/helpers/ui/comparator.service.js.map |
| 2102 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2103 | 'use strict'; |
| 2104 | |
| 2105 | (function () { |
| 2106 | 'use strict'; |
| 2107 | |
| 2108 | /** |
| 2109 | * @ngdoc overview |
| 2110 | * @name xos.helpers |
| 2111 | * @description |
| 2112 | * # xos.Helpers |
| 2113 | * A collection of helpers to work with XOS <br/> |
| 2114 | * Currently available components are: |
| 2115 | * - [NoHyperlinks](/#/module/xos.helpers.NoHyperlinks) |
| 2116 | * - [SetCSRFToken](/#/module/xos.helpers.SetCSRFToken) |
| 2117 | * - [xosNotification](/#/module/xos.helpers.xosNotification) |
| 2118 | * - [XosUserPrefs](/#/module/xos.helpers.XosUserPrefs) |
| 2119 | * <br/><br/> |
| 2120 | * A set of angular [$resource](https://docs.angularjs.org/api/ngResource/service/$resource) is provided to work with the API.<br> |
| 2121 | * You can find the documentation [here](#/rest-api) |
| 2122 | **/ |
| 2123 | |
| 2124 | config.$inject = ["$httpProvider", "$interpolateProvider", "$resourceProvider"]; |
| 2125 | angular.module('xos.helpers', ['ngCookies', 'ngResource', 'ngAnimate', 'xos.uiComponents']).config(config) |
| 2126 | |
| 2127 | /** |
| 2128 | * @ngdoc service |
| 2129 | * @name xos.helpers._ |
| 2130 | * @description Wrap [lodash](https://lodash.com/docs) in an Angular Service |
| 2131 | **/ |
| 2132 | |
| 2133 | .factory('_', ["$window", function ($window) { |
| 2134 | return $window._; |
| 2135 | }]); |
| 2136 | |
| 2137 | function config($httpProvider, $interpolateProvider, $resourceProvider) { |
| 2138 | $httpProvider.interceptors.push('SetCSRFToken'); |
| 2139 | |
| 2140 | // NOTE http://www.masnun.com/2013/09/18/django-rest-framework-angularjs-resource-trailing-slash-problem.html |
| 2141 | $resourceProvider.defaults.stripTrailingSlashes = false; |
| 2142 | } |
| 2143 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2144 | //# sourceMappingURL=maps/xosHelpers.module.js.map |
| 2145 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2146 | 'use strict'; |
| 2147 | |
| 2148 | (function () { |
| 2149 | 'use strict'; |
| 2150 | |
| 2151 | angular.module('xos.helpers') |
| 2152 | /** |
| 2153 | * @ngdoc service |
| 2154 | * @name xos.helpers.vSG-Collection |
| 2155 | * @description Angular resource to fetch /api/service/vsg/ |
| 2156 | **/ |
| 2157 | .service('vSG-Collection', ["$resource", function ($resource) { |
| 2158 | return $resource('/api/service/vsg/'); |
| 2159 | }]); |
| 2160 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2161 | //# sourceMappingURL=../../maps/services/rest/vSG.js.map |
| 2162 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2163 | 'use strict'; |
| 2164 | |
| 2165 | (function () { |
| 2166 | 'use strict'; |
| 2167 | |
| 2168 | angular.module('xos.helpers') |
| 2169 | /** |
| 2170 | * @ngdoc service |
| 2171 | * @name xos.helpers.vOLT-Collection |
| 2172 | * @description Angular resource to fetch /api/tenant/cord/volt/:volt_id/ |
| 2173 | **/ |
| 2174 | .service('vOLT-Collection', ["$resource", function ($resource) { |
| 2175 | return $resource('/api/tenant/cord/volt/:volt_id/', { volt_id: '@id' }, { |
| 2176 | update: { method: 'PUT' } |
| 2177 | }); |
| 2178 | }]); |
| 2179 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2180 | //# sourceMappingURL=../../maps/services/rest/vOLT.js.map |
| 2181 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2182 | 'use strict'; |
| 2183 | |
| 2184 | (function () { |
| 2185 | 'use strict'; |
| 2186 | |
| 2187 | angular.module('xos.helpers') |
| 2188 | /** |
| 2189 | * @ngdoc service |
| 2190 | * @name xos.helpers.Login |
| 2191 | * @description Angular resource to fetch /api/utility/login/ |
| 2192 | **/ |
| 2193 | .service('Login', ["$resource", function ($resource) { |
| 2194 | return $resource('/api/utility/login/'); |
| 2195 | }]) |
| 2196 | /** |
| 2197 | * @ngdoc service |
| 2198 | * @name xos.helpers.Logout |
| 2199 | * @description Angular resource to fetch /api/utility/logout/ |
| 2200 | **/ |
| 2201 | .service('Logout', ["$resource", function ($resource) { |
| 2202 | return $resource('/api/utility/logout/'); |
| 2203 | }]); |
| 2204 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2205 | //# sourceMappingURL=../../maps/services/rest/Utility.js.map |
| 2206 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2207 | 'use strict'; |
| 2208 | |
| 2209 | (function () { |
| 2210 | 'use strict'; |
| 2211 | |
| 2212 | angular.module('xos.helpers') |
| 2213 | /** |
| 2214 | * @ngdoc service |
| 2215 | * @name xos.helpers.Users |
| 2216 | * @description Angular resource to fetch /api/core/users/:id/ |
| 2217 | **/ |
| 2218 | .service('Users', ["$resource", function ($resource) { |
| 2219 | return $resource('/api/core/users/:id/', { id: '@id' }, { |
| 2220 | update: { method: 'PUT' } |
| 2221 | }); |
| 2222 | }]); |
| 2223 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2224 | //# sourceMappingURL=../../maps/services/rest/Users.js.map |
| 2225 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2226 | 'use strict'; |
| 2227 | |
| 2228 | (function () { |
| 2229 | 'use strict'; |
| 2230 | |
| 2231 | angular.module('xos.helpers') |
| 2232 | /** |
| 2233 | * @ngdoc service |
| 2234 | * @name xos.helpers.Truckroll |
| 2235 | * @description Angular resource to fetch /api/tenant/truckroll/:id/ |
| 2236 | **/ |
| 2237 | .service('Truckroll', ["$resource", function ($resource) { |
| 2238 | return $resource('/api/tenant/truckroll/:id/', { id: '@id' }, { |
| 2239 | update: { method: 'PUT' } |
| 2240 | }); |
| 2241 | }]); |
| 2242 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2243 | //# sourceMappingURL=../../maps/services/rest/Truckroll.js.map |
| 2244 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2245 | 'use strict'; |
| 2246 | |
| 2247 | (function () { |
| 2248 | 'use strict'; |
| 2249 | |
| 2250 | angular.module('xos.helpers') |
| 2251 | /** |
| 2252 | * @ngdoc service |
| 2253 | * @name xos.helpers.Tenant |
| 2254 | * @description Angular resource to fetch /api/core/tenant/:id/ |
| 2255 | **/ |
| 2256 | .service('Tenants', ["$resource", function ($resource) { |
| 2257 | return $resource('/api/core/tenants/:id/', { id: '@id' }, { |
| 2258 | update: { method: 'PUT' } |
| 2259 | }); |
| 2260 | }]); |
| 2261 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2262 | //# sourceMappingURL=../../maps/services/rest/Tenant.js.map |
| 2263 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2264 | 'use strict'; |
| 2265 | |
| 2266 | (function () { |
| 2267 | 'use strict'; |
| 2268 | |
| 2269 | angular.module('xos.helpers') |
| 2270 | /** |
| 2271 | * @ngdoc service |
| 2272 | * @name xos.helpers.Subscribers |
| 2273 | * @description Angular resource to fetch Subscribers |
| 2274 | **/ |
| 2275 | .service('Subscribers', ["$resource", function ($resource) { |
| 2276 | return $resource('/api/tenant/cord/subscriber/:id/', { id: '@id' }, { |
| 2277 | update: { method: 'PUT' }, |
| 2278 | /** |
| 2279 | * @ngdoc method |
| 2280 | * @name xos.helpers.Subscribers#View-a-Subscriber-Features-Detail |
| 2281 | * @methodOf xos.helpers.Subscribers |
| 2282 | * @description |
| 2283 | * View-a-Subscriber-Features-Detail |
| 2284 | **/ |
| 2285 | 'View-a-Subscriber-Features-Detail': { |
| 2286 | method: 'GET', |
| 2287 | isArray: false, |
| 2288 | url: '/api/tenant/cord/subscriber/:id/features/' |
| 2289 | }, |
| 2290 | /** |
| 2291 | * @ngdoc method |
| 2292 | * @name xos.helpers.Subscribers#Read-Subscriber-uplink_speed |
| 2293 | * @methodOf xos.helpers.Subscribers |
| 2294 | * @description |
| 2295 | * Read-Subscriber-uplink_speed |
| 2296 | **/ |
| 2297 | 'Read-Subscriber-uplink_speed': { |
| 2298 | method: 'GET', |
| 2299 | isArray: false, |
| 2300 | url: '/api/tenant/cord/subscriber/:id/features/uplink_speed/' |
| 2301 | }, |
| 2302 | /** |
| 2303 | * @ngdoc method |
| 2304 | * @name xos.helpers.Subscribers#Update-Subscriber-uplink_speed |
| 2305 | * @methodOf xos.helpers.Subscribers |
| 2306 | * @description |
| 2307 | * Update-Subscriber-uplink_speed |
| 2308 | **/ |
| 2309 | 'Update-Subscriber-uplink_speed': { |
| 2310 | method: 'PUT', |
| 2311 | isArray: false, |
| 2312 | url: '/api/tenant/cord/subscriber/:id/features/uplink_speed/' |
| 2313 | }, |
| 2314 | /** |
| 2315 | * @ngdoc method |
| 2316 | * @name xos.helpers.Subscribers#Read-Subscriber-downlink_speed |
| 2317 | * @methodOf xos.helpers.Subscribers |
| 2318 | * @description |
| 2319 | * Read-Subscriber-downlink_speed |
| 2320 | **/ |
| 2321 | 'Read-Subscriber-downlink_speed': { |
| 2322 | method: 'GET', |
| 2323 | isArray: false, |
| 2324 | url: '/api/tenant/cord/subscriber/:id/features/downlink_speed/' |
| 2325 | }, |
| 2326 | /** |
| 2327 | * @ngdoc method |
| 2328 | * @name xos.helpers.Subscribers#Update-Subscriber-downlink_speed |
| 2329 | * @methodOf xos.helpers.Subscribers |
| 2330 | * @description |
| 2331 | * Update-Subscriber-downlink_speed |
| 2332 | **/ |
| 2333 | 'Update-Subscriber-downlink_speed': { |
| 2334 | method: 'PUT', |
| 2335 | isArray: false, |
| 2336 | url: '/api/tenant/cord/subscriber/:id/features/downlink_speed/' |
| 2337 | }, |
| 2338 | /** |
| 2339 | * @ngdoc method |
| 2340 | * @name xos.helpers.Subscribers#Read-Subscriber-cdn |
| 2341 | * @methodOf xos.helpers.Subscribers |
| 2342 | * @description |
| 2343 | * Read-Subscriber-cdn |
| 2344 | **/ |
| 2345 | 'Read-Subscriber-cdn': { |
| 2346 | method: 'GET', |
| 2347 | isArray: false, |
| 2348 | url: '/api/tenant/cord/subscriber/:id/features/cdn/' |
| 2349 | }, |
| 2350 | /** |
| 2351 | * @ngdoc method |
| 2352 | * @name xos.helpers.Subscribers#Update-Subscriber-cdn |
| 2353 | * @methodOf xos.helpers.Subscribers |
| 2354 | * @description |
| 2355 | * Update-Subscriber-cdn |
| 2356 | **/ |
| 2357 | 'Update-Subscriber-cdn': { |
| 2358 | method: 'PUT', |
| 2359 | isArray: false, |
| 2360 | url: '/api/tenant/cord/subscriber/:id/features/cdn/' |
| 2361 | }, |
| 2362 | /** |
| 2363 | * @ngdoc method |
| 2364 | * @name xos.helpers.Subscribers#Read-Subscriber-uverse |
| 2365 | * @methodOf xos.helpers.Subscribers |
| 2366 | * @description |
| 2367 | * Read-Subscriber-uverse |
| 2368 | **/ |
| 2369 | 'Read-Subscriber-uverse': { |
| 2370 | method: 'GET', |
| 2371 | isArray: false, |
| 2372 | url: '/api/tenant/cord/subscriber/:id/features/uverse/' |
| 2373 | }, |
| 2374 | /** |
| 2375 | * @ngdoc method |
| 2376 | * @name xos.helpers.Subscribers#Update-Subscriber-uverse |
| 2377 | * @methodOf xos.helpers.Subscribers |
| 2378 | * @description |
| 2379 | * Update-Subscriber-uverse |
| 2380 | **/ |
| 2381 | 'Update-Subscriber-uverse': { |
| 2382 | method: 'PUT', |
| 2383 | isArray: false, |
| 2384 | url: '/api/tenant/cord/subscriber/:id/features/uverse/' |
| 2385 | }, |
| 2386 | /** |
| 2387 | * @ngdoc method |
| 2388 | * @name xos.helpers.Subscribers#Read-Subscriber-status |
| 2389 | * @methodOf xos.helpers.Subscribers |
| 2390 | * @description |
| 2391 | * Read-Subscriber-status |
| 2392 | **/ |
| 2393 | 'Read-Subscriber-status': { |
| 2394 | method: 'GET', |
| 2395 | isArray: false, |
| 2396 | url: '/api/tenant/cord/subscriber/:id/features/status/' |
| 2397 | }, |
| 2398 | /** |
| 2399 | * @ngdoc method |
| 2400 | * @name xos.helpers.Subscribers#Update-Subscriber-status |
| 2401 | * @methodOf xos.helpers.Subscribers |
| 2402 | * @description |
| 2403 | * Update-Subscriber-status |
| 2404 | **/ |
| 2405 | 'Update-Subscriber-status': { |
| 2406 | method: 'PUT', |
| 2407 | isArray: false, |
| 2408 | url: '/api/tenant/cord/subscriber/:id/features/status/' |
| 2409 | } |
| 2410 | }); |
| 2411 | }]); |
| 2412 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2413 | //# sourceMappingURL=../../maps/services/rest/Subscribers.js.map |
| 2414 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2415 | 'use strict'; |
| 2416 | |
| 2417 | (function () { |
| 2418 | 'use strict'; |
| 2419 | |
| 2420 | angular.module('xos.helpers') |
| 2421 | /** |
| 2422 | * @ngdoc service |
| 2423 | * @name xos.helpers.SlicesPlus |
| 2424 | * @description Angular resource to fetch /api/utility/slicesplus/ |
| 2425 | * This is a read-only API and only the `query` method is currently supported. |
| 2426 | **/ |
| 2427 | .service('SlicesPlus', ["$http", "$q", function ($http, $q) { |
| 2428 | this.query = function (params) { |
| 2429 | var deferred = $q.defer(); |
| 2430 | |
| 2431 | $http.get('/api/utility/slicesplus/', { params: params }).then(function (res) { |
| 2432 | deferred.resolve(res.data); |
| 2433 | }).catch(function (res) { |
| 2434 | deferred.reject(res.data); |
| 2435 | }); |
| 2436 | |
| 2437 | return { $promise: deferred.promise }; |
| 2438 | }; |
| 2439 | |
| 2440 | this.get = function (id, params) { |
| 2441 | var deferred = $q.defer(); |
| 2442 | |
| 2443 | $http.get('/api/utility/slicesplus/' + id, { params: params }).then(function (res) { |
| 2444 | deferred.resolve(res.data); |
| 2445 | }).catch(function (res) { |
| 2446 | deferred.reject(res.data); |
| 2447 | }); |
| 2448 | return { $promise: deferred.promise }; |
| 2449 | }; |
| 2450 | }]); |
| 2451 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2452 | //# sourceMappingURL=../../maps/services/rest/Slices_plus.js.map |
| 2453 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2454 | 'use strict'; |
| 2455 | |
| 2456 | (function () { |
| 2457 | 'use strict'; |
| 2458 | |
| 2459 | angular.module('xos.helpers') |
| 2460 | /** |
| 2461 | * @ngdoc service |
| 2462 | * @name xos.helpers.Slices |
| 2463 | * @description Angular resource to fetch /api/core/slices/:id/ |
| 2464 | **/ |
| 2465 | .service('Slices', ["$resource", function ($resource) { |
| 2466 | return $resource('/api/core/slices/:id/', { id: '@id' }, { |
| 2467 | update: { method: 'PUT' } |
| 2468 | }); |
| 2469 | }]); |
| 2470 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2471 | //# sourceMappingURL=../../maps/services/rest/Slices.js.map |
| 2472 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2473 | 'use strict'; |
| 2474 | |
| 2475 | (function () { |
| 2476 | 'use strict'; |
| 2477 | |
| 2478 | angular.module('xos.helpers') |
| 2479 | /** |
| 2480 | * @ngdoc service |
| 2481 | * @name xos.helpers.Sites |
| 2482 | * @description Angular resource to fetch /api/core/sites/:id/ |
| 2483 | **/ |
| 2484 | .service('Sites', ["$resource", function ($resource) { |
| 2485 | return $resource('/api/core/sites/:id/', { id: '@id' }, { |
| 2486 | update: { method: 'PUT' } |
| 2487 | }); |
| 2488 | }]); |
| 2489 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2490 | //# sourceMappingURL=../../maps/services/rest/Sites.js.map |
| 2491 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2492 | 'use strict'; |
| 2493 | |
| 2494 | (function () { |
| 2495 | 'use strict'; |
| 2496 | |
| 2497 | angular.module('xos.helpers') |
| 2498 | /** |
| 2499 | * @ngdoc service |
| 2500 | * @name xos.helpers.Services |
| 2501 | * @description Angular resource to fetch /api/core/services/:id/ |
| 2502 | **/ |
| 2503 | .service('Services', ["$resource", function ($resource) { |
| 2504 | return $resource('/api/core/services/:id/', { id: '@id' }, { |
| 2505 | update: { method: 'PUT' } |
| 2506 | }); |
| 2507 | }]); |
| 2508 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2509 | //# sourceMappingURL=../../maps/services/rest/Services.js.map |
| 2510 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2511 | 'use strict'; |
| 2512 | |
| 2513 | (function () { |
| 2514 | 'use strict'; |
| 2515 | |
| 2516 | angular.module('xos.helpers') |
| 2517 | /** |
| 2518 | * @ngdoc service |
| 2519 | * @name xos.helpers.ONOS-Services-Collection |
| 2520 | * @description Angular resource to fetch /api/service/onos/ |
| 2521 | **/ |
| 2522 | .service('ONOS-Services-Collection', ["$resource", function ($resource) { |
| 2523 | return $resource('/api/service/onos/'); |
| 2524 | }]); |
| 2525 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2526 | //# sourceMappingURL=../../maps/services/rest/ONOS-Services.js.map |
| 2527 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2528 | 'use strict'; |
| 2529 | |
| 2530 | (function () { |
| 2531 | 'use strict'; |
| 2532 | |
| 2533 | angular.module('xos.helpers') |
| 2534 | /** |
| 2535 | * @ngdoc service |
| 2536 | * @name xos.helpers.ONOS-App-Collection |
| 2537 | * @description Angular resource to fetch /api/tenant/onos/app/ |
| 2538 | **/ |
| 2539 | .service('ONOS-App-Collection', ["$resource", function ($resource) { |
| 2540 | return $resource('/api/tenant/onos/app/'); |
| 2541 | }]); |
| 2542 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2543 | //# sourceMappingURL=../../maps/services/rest/ONOS-Apps.js.map |
| 2544 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2545 | 'use strict'; |
| 2546 | |
| 2547 | (function () { |
| 2548 | 'use strict'; |
| 2549 | |
| 2550 | angular.module('xos.helpers') |
| 2551 | /** |
| 2552 | * @ngdoc service |
| 2553 | * @name xos.helpers.Nodes |
| 2554 | * @description Angular resource to fetch /api/core/nodes/:id/ |
| 2555 | **/ |
| 2556 | .service('Nodes', ["$resource", function ($resource) { |
| 2557 | return $resource('/api/core/nodes/:id/', { id: '@id' }, { |
| 2558 | update: { method: 'PUT' } |
| 2559 | }); |
| 2560 | }]); |
| 2561 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2562 | //# sourceMappingURL=../../maps/services/rest/Nodes.js.map |
| 2563 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2564 | 'use strict'; |
| 2565 | |
| 2566 | (function () { |
| 2567 | 'use strict'; |
| 2568 | |
| 2569 | angular.module('xos.helpers') |
| 2570 | /** |
| 2571 | * @ngdoc service |
| 2572 | * @name xos.helpers.Networkstemplates |
| 2573 | * @description Angular resource to fetch /api/core/networktemplates/:id/ |
| 2574 | **/ |
| 2575 | .service('Networkstemplates', ["$resource", function ($resource) { |
| 2576 | return $resource('/api/core/networktemplates/:id/', { id: '@id' }, { |
| 2577 | update: { method: 'PUT' } |
| 2578 | }); |
| 2579 | }]); |
| 2580 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2581 | //# sourceMappingURL=../../maps/services/rest/Networkstemplates.js.map |
| 2582 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2583 | 'use strict'; |
| 2584 | |
| 2585 | (function () { |
| 2586 | 'use strict'; |
| 2587 | |
| 2588 | angular.module('xos.helpers') |
| 2589 | /** |
| 2590 | * @ngdoc service |
| 2591 | * @name xos.helpers.Networks |
| 2592 | * @description Angular resource to fetch /api/core/networks/:id/ |
| 2593 | **/ |
| 2594 | .service('Networks', ["$resource", function ($resource) { |
| 2595 | return $resource('/api/core/networks/:id/', { id: '@id' }, { |
| 2596 | update: { method: 'PUT' } |
| 2597 | }); |
| 2598 | }]); |
| 2599 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2600 | //# sourceMappingURL=../../maps/services/rest/Networks.js.map |
| 2601 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2602 | 'use strict'; |
| 2603 | |
| 2604 | (function () { |
| 2605 | 'use strict'; |
| 2606 | |
| 2607 | angular.module('xos.helpers') |
| 2608 | /**
|
| 2609 | * @ngdoc service
|
| 2610 | * @name xos.helpers.Me
|
| 2611 | * @description Http read-only api to fetch /api/utility/me/
|
| 2612 | **/ |
| 2613 | .service('Me', ["$q", "$http", function ($q, $http) { |
| 2614 | |
| 2615 | this.get = function () { |
| 2616 | var deferred = $q.defer(); |
| 2617 | |
| 2618 | $http.get('/api/utility/me/').then(function (res) { |
| 2619 | deferred.resolve(res.data); |
| 2620 | }).catch(function (e) { |
| 2621 | deferred.reject(e); |
| 2622 | }); |
| 2623 | return deferred.promise; |
| 2624 | }; |
| 2625 | }]); |
| 2626 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2627 | //# sourceMappingURL=../../maps/services/rest/Me.js.map |
| 2628 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2629 | 'use strict'; |
| 2630 | |
| 2631 | (function () { |
| 2632 | 'use strict'; |
| 2633 | |
| 2634 | angular.module('xos.helpers') |
| 2635 | /** |
| 2636 | * @ngdoc service |
| 2637 | * @name xos.helpers.Instances |
| 2638 | * @description Angular resource to fetch /api/core/instances/:id/ |
| 2639 | **/ |
| 2640 | .service('Instances', ["$resource", function ($resource) { |
| 2641 | return $resource('/api/core/instances/:id/', { id: '@id' }, { |
| 2642 | update: { method: 'PUT' } |
| 2643 | }); |
| 2644 | }]); |
| 2645 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2646 | //# sourceMappingURL=../../maps/services/rest/Instances.js.map |
| 2647 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2648 | 'use strict'; |
| 2649 | |
| 2650 | (function () { |
| 2651 | 'use strict'; |
| 2652 | |
| 2653 | angular.module('xos.helpers') |
| 2654 | /** |
| 2655 | * @ngdoc service |
| 2656 | * @name xos.helpers.Images |
| 2657 | * @description Angular resource to fetch /api/core/images/ |
| 2658 | **/ |
| 2659 | .service('Images', ["$resource", function ($resource) { |
| 2660 | return $resource('/api/core/images/:id/', { id: '@id' }, { |
| 2661 | update: { method: 'PUT' } |
| 2662 | }); |
| 2663 | }]); |
| 2664 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2665 | //# sourceMappingURL=../../maps/services/rest/Images.js.map |
| 2666 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2667 | 'use strict'; |
| 2668 | |
| 2669 | (function () { |
| 2670 | 'use strict'; |
| 2671 | |
| 2672 | angular.module('xos.helpers') |
| 2673 | /** |
| 2674 | * @ngdoc service |
| 2675 | * @name xos.helpers.Flavors |
| 2676 | * @description Angular resource to fetch /api/core/flavors/:id/ |
| 2677 | **/ |
| 2678 | .service('Flavors', ["$resource", function ($resource) { |
| 2679 | return $resource('/api/core/flavors/:id/', { id: '@id' }, { |
| 2680 | update: { method: 'PUT' } |
| 2681 | }); |
| 2682 | }]); |
| 2683 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2684 | //# sourceMappingURL=../../maps/services/rest/Flavors.js.map |
| 2685 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2686 | 'use strict'; |
| 2687 | |
| 2688 | (function () { |
| 2689 | 'use strict'; |
| 2690 | |
| 2691 | angular.module('xos.helpers') |
| 2692 | /** |
| 2693 | * @ngdoc service |
| 2694 | * @name xos.helpers.Example-Services-Collection |
| 2695 | * @description Angular resource to fetch /api/service/exampleservice/ |
| 2696 | **/ |
| 2697 | .service('Example-Services-Collection', ["$resource", function ($resource) { |
| 2698 | return $resource('/api/service/exampleservice/'); |
| 2699 | }]); |
| 2700 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2701 | //# sourceMappingURL=../../maps/services/rest/Example.js.map |
| 2702 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2703 | 'use strict'; |
| 2704 | |
| 2705 | (function () { |
| 2706 | 'use strict'; |
| 2707 | |
| 2708 | angular.module('xos.helpers') |
| 2709 | /** |
| 2710 | * @ngdoc service |
| 2711 | * @name xos.helpers.Deployments |
| 2712 | * @description Angular resource to fetch /api/core/deployments/:id/ |
| 2713 | **/ |
| 2714 | .service('Deployments', ["$resource", function ($resource) { |
| 2715 | return $resource('/api/core/deployments/:id/', { id: '@id' }, { |
| 2716 | update: { method: 'PUT' } |
| 2717 | }); |
| 2718 | }]); |
| 2719 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2720 | //# sourceMappingURL=../../maps/services/rest/Deployments.js.map |
| 2721 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2722 | 'use strict'; |
| 2723 | |
| 2724 | (function () { |
| 2725 | 'use strict'; |
| 2726 | |
| 2727 | angular.module('xos.helpers') |
| 2728 | /** |
| 2729 | * @ngdoc service |
| 2730 | * @name xos.helpers.Dashboards |
| 2731 | * @description Angular resource to fetch /api/core/dashboardviews/:id/ |
| 2732 | **/ |
| 2733 | .service('Dashboards', ["$resource", "$q", "$http", function ($resource, $q, $http) { |
| 2734 | var r = $resource('/api/core/dashboardviews/:id/', { id: '@id' }, { |
| 2735 | update: { method: 'PUT' } |
| 2736 | }); |
| 2737 | |
| 2738 | r.prototype.$save = function () { |
| 2739 | var d = $q.defer(); |
| 2740 | |
| 2741 | $http.put('/api/core/dashboardviews/' + this.id + '/', this).then(function (res) { |
| 2742 | d.resolve(res.data); |
| 2743 | }).catch(function (e) { |
| 2744 | d.reject(e.data); |
| 2745 | }); |
| 2746 | |
| 2747 | return d.promise; |
| 2748 | }; |
| 2749 | |
| 2750 | return r; |
| 2751 | }]); |
| 2752 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2753 | //# sourceMappingURL=../../maps/services/rest/Dashboards.js.map |
| 2754 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2755 | 'use strict'; |
| 2756 | |
| 2757 | (function () { |
| 2758 | |
| 2759 | angular.module('xos.helpers') |
| 2760 | |
| 2761 | /**
|
| 2762 | * @ngdoc service
|
| 2763 | * @name xos.helpers.XosUserPrefs
|
| 2764 | * @description
|
| 2765 | * This service is used to store the user preferences in cookies, so that they survive to page changes.
|
| 2766 | * The structure of the user preference is:
|
| 2767 | * ```
|
| 2768 | * {
|
| 2769 | * synchronizers: {
|
| 2770 | * notification: {
|
| 2771 | * 'volt': boolean,
|
| 2772 | * 'openstack': boolean,
|
| 2773 | * ...
|
| 2774 | * }
|
| 2775 | * }
|
| 2776 | * userData: {
|
| 2777 | * current_user_site_id: Number,
|
| 2778 | * current_user_site_user_names: Array[1],
|
| 2779 | * ...
|
| 2780 | * }
|
| 2781 | * }
|
| 2782 | * ```
|
| 2783 | **/ |
| 2784 | |
| 2785 | .service('XosUserPrefs', ["$cookies", "Me", "$q", function ($cookies, Me, $q) { |
| 2786 | var _this = this; |
| 2787 | |
| 2788 | var userPrefs = $cookies.get('xosUserPrefs') ? angular.fromJson($cookies.get('xosUserPrefs')) : {}; |
| 2789 | |
| 2790 | /**
|
| 2791 | * @ngdoc method
|
| 2792 | * @name xos.helpers.XosUserPrefs#getAll
|
| 2793 | * @methodOf xos.helpers.XosUserPrefs
|
| 2794 | * @description
|
| 2795 | * Return all the user preferences stored in cookies
|
| 2796 | * @returns {object} The user preferences
|
| 2797 | **/ |
| 2798 | this.getAll = function () { |
| 2799 | userPrefs = $cookies.get('xosUserPrefs') ? angular.fromJson($cookies.get('xosUserPrefs')) : {}; |
| 2800 | return userPrefs; |
| 2801 | }; |
| 2802 | |
| 2803 | /**
|
| 2804 | * @ngdoc method
|
| 2805 | * @name xos.helpers.XosUserPrefs#setAll
|
| 2806 | * @methodOf xos.helpers.XosUserPrefs
|
| 2807 | * @description
|
| 2808 | * Override all user preferences
|
| 2809 | * @param {object} prefs The user preferences
|
| 2810 | **/ |
| 2811 | this.setAll = function (prefs) { |
| 2812 | $cookies.put('xosUserPrefs', angular.toJson(prefs)); |
| 2813 | }; |
| 2814 | |
| 2815 | /**
|
| 2816 | * @ngdoc method
|
| 2817 | * @name xos.helpers.XosUserPrefs#getSynchronizerNotificationStatus
|
| 2818 | * @methodOf xos.helpers.XosUserPrefs
|
| 2819 | * @description
|
| 2820 | * Return the synchronizer notification status, if name is not provided return the status for all synchronizers
|
| 2821 | * @param {string=} prefs The synchronizer name
|
| 2822 | * @returns {object | string} The synchronizer status
|
| 2823 | **/ |
| 2824 | this.getSynchronizerNotificationStatus = function () { |
| 2825 | var name = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; |
| 2826 | |
| 2827 | if (name) { |
| 2828 | return _this.getAll().synchronizers.notification[name]; |
| 2829 | } |
| 2830 | return _this.getAll().synchronizers.notification; |
| 2831 | }; |
| 2832 | |
| 2833 | /**
|
| 2834 | * @ngdoc method
|
| 2835 | * @name xos.helpers.XosUserPrefs#getUserDetailsCookie
|
| 2836 | * @methodOf xos.helpers.XosUserPrefs
|
| 2837 | * @description
|
| 2838 | * Return all the user details stored in cookies or call the service
|
| 2839 | * @returns {object} The user details
|
| 2840 | **/ |
| 2841 | this.getUserDetailsCookie = function () { |
| 2842 | var defer = $q.defer(); |
| 2843 | var localPref = _this.getAll(); |
| 2844 | if (!localPref.userData) { |
| 2845 | _this.setUserDetailsCookie().$promise.then(function (data) { |
| 2846 | defer.resolve(data); |
| 2847 | }); |
| 2848 | } else { |
| 2849 | defer.resolve(localPref.userData); |
| 2850 | } |
| 2851 | return { $promise: defer.promise }; |
| 2852 | }; |
| 2853 | |
| 2854 | /**
|
| 2855 | * @ngdoc method
|
| 2856 | * @name xos.helpers.XosUserPrefs#setUserDetailsCookie
|
| 2857 | * @methodOf xos.helpers.XosUserPrefs
|
| 2858 | * @description
|
| 2859 | * Save the user details in the cookie
|
| 2860 | * @param {object} details stored in cookie
|
| 2861 | * @param {objects} returns the user details as a promise
|
| 2862 | **/ |
| 2863 | this.setUserDetailsCookie = function () { |
| 2864 | var userData = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; |
| 2865 | |
| 2866 | |
| 2867 | var defer = $q.defer(); |
| 2868 | var cookies = _this.getAll(); |
| 2869 | if (!userData) { |
| 2870 | Me.get().then(function (user) { |
| 2871 | cookies.userData = user; |
| 2872 | _this.setAll(cookies); |
| 2873 | defer.resolve(user); |
| 2874 | }).catch(function (e) { |
| 2875 | defer.reject(e); |
| 2876 | }); |
| 2877 | } else { |
| 2878 | cookies.userData = userData; |
| 2879 | _this.setAll(cookies); |
| 2880 | defer.resolve(userData); |
| 2881 | } |
| 2882 | return { $promise: defer.promise }; |
| 2883 | }; |
| 2884 | |
| 2885 | /**
|
| 2886 | * @ngdoc method
|
| 2887 | * @name xos.helpers.XosUserPrefs#setSynchronizerNotificationStatus
|
| 2888 | * @methodOf xos.helpers.XosUserPrefs
|
| 2889 | * @description
|
| 2890 | * Update the notification status for a single synchronizer
|
| 2891 | * @param {string} name The synchronizer name
|
| 2892 | * @param {boolean} value The notification status (true means that it has been sent)
|
| 2893 | **/ |
| 2894 | |
| 2895 | this.setSynchronizerNotificationStatus = function () { |
| 2896 | var name = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; |
| 2897 | var value = arguments[1]; |
| 2898 | |
| 2899 | if (!name) { |
| 2900 | throw new Error('[XosUserPrefs] When updating a synchronizer is mandatory to provide a name.'); |
| 2901 | } |
| 2902 | |
| 2903 | var cookies = _this.getAll(); |
| 2904 | |
| 2905 | if (!cookies.synchronizers) { |
| 2906 | cookies.synchronizers = { |
| 2907 | notification: {} |
| 2908 | }; |
| 2909 | } |
| 2910 | cookies.synchronizers.notification[name] = value; |
| 2911 | _this.setAll(cookies); |
| 2912 | }; |
| 2913 | }]); |
| 2914 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2915 | //# sourceMappingURL=../../maps/services/helpers/user-prefs.service.js.map |
| 2916 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2917 | 'use strict'; |
| 2918 | |
| 2919 | (function () { |
| 2920 | 'use strict'; |
| 2921 | |
| 2922 | /** |
| 2923 | * @ngdoc service |
| 2924 | * @name xos.helpers.ServiceGraph |
| 2925 | * @description This factory define a set of helper function to query the service tenancy graph |
| 2926 | **/ |
| 2927 | |
| 2928 | angular.module('xos.helpers').service('GraphService', ["$q", "Tenants", "Services", function ($q, Tenants, Services) { |
| 2929 | var _this = this; |
| 2930 | |
| 2931 | this.loadCoarseData = function () { |
| 2932 | |
| 2933 | var services = void 0; |
| 2934 | |
| 2935 | var deferred = $q.defer(); |
| 2936 | |
| 2937 | Services.query().$promise.then(function (res) { |
| 2938 | services = res; |
| 2939 | return Tenants.query({ kind: 'coarse' }).$promise; |
| 2940 | }).then(function (tenants) { |
| 2941 | deferred.resolve({ |
| 2942 | tenants: tenants, |
| 2943 | services: services |
| 2944 | }); |
| 2945 | }); |
| 2946 | |
| 2947 | return deferred.promise; |
| 2948 | }; |
| 2949 | |
| 2950 | this.getCoarseGraph = function () { |
| 2951 | _this.loadCoarseData().then(function (res) { |
| 2952 | console.log(res); |
| 2953 | }); |
| 2954 | return 'ciao'; |
| 2955 | }; |
| 2956 | }]); |
| 2957 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 2958 | //# sourceMappingURL=../maps/services/service_graph.service.js.map |
| 2959 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2960 | 'use strict'; |
| 2961 | |
| 2962 | /* eslint-disable angular/ng_window_service*/ |
| 2963 | (function () { |
| 2964 | 'use strict'; |
| 2965 | |
| 2966 | angular.module('xos.helpers').factory('Notification', function () { |
| 2967 | return window.Notification; |
| 2968 | }) |
| 2969 | /** |
| 2970 | * @ngdoc service |
| 2971 | * @name xos.helpers.xosNotification |
| 2972 | * @description This factory define a set of helper function to trigger desktop notification |
| 2973 | **/ |
| 2974 | .service('xosNotification', ["$q", "$log", "Notification", function ($q, $log, Notification) { |
| 2975 | var _this = this; |
| 2976 | |
| 2977 | this.checkPermission = function () { |
| 2978 | var deferred = $q.defer(); |
| 2979 | Notification.requestPermission().then(function (permission) { |
| 2980 | if (permission === 'granted') { |
| 2981 | deferred.resolve(permission); |
| 2982 | } else { |
| 2983 | deferred.reject(permission); |
| 2984 | } |
| 2985 | }); |
| 2986 | return deferred.promise; |
| 2987 | }; |
| 2988 | |
| 2989 | this.sendNotification = function (title, options) { |
| 2990 | var notification = new Notification(title, options); |
| 2991 | notification.onerror = function (err) { |
| 2992 | $log.error(err); |
| 2993 | }; |
| 2994 | }; |
| 2995 | |
| 2996 | /** |
| 2997 | * @ngdoc method |
| 2998 | * @name xos.helpers.xosNotification#notify |
| 2999 | * @methodOf xos.helpers.xosNotification |
| 3000 | * @description |
| 3001 | * This method will check for user permission and if granted will send a browser notification. |
| 3002 | * @param {string} title The notification title |
| 3003 | * @param {object} options The notification options: `{icon: 'url', body: 'Notification body'}` |
| 3004 | **/ |
| 3005 | |
| 3006 | this.notify = function (title, options) { |
| 3007 | if (!('Notification' in window)) { |
| 3008 | $log.info('This browser does not support desktop notification'); |
| 3009 | } else if (Notification.permission !== 'granted') { |
| 3010 | _this.checkPermission().then(function () { |
| 3011 | return _this.sendNotification(title, options); |
| 3012 | }); |
| 3013 | } else if (Notification.permission === 'granted') { |
| 3014 | _this.sendNotification(title, options); |
| 3015 | } |
| 3016 | }; |
| 3017 | }]); |
| 3018 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 3019 | //# sourceMappingURL=../maps/services/notification.service.js.map |
| 3020 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 3021 | 'use strict'; |
| 3022 | |
| 3023 | (function () { |
| 3024 | 'use strict'; |
| 3025 | |
| 3026 | /** |
| 3027 | * @ngdoc service |
| 3028 | * @name xos.helpers.NoHyperlinks |
| 3029 | * @description This factory is automatically loaded trough xos.helpers and will add an $http interceptor that will add ?no_hyperlinks=1 to your api request, that is required by django |
| 3030 | **/ |
| 3031 | |
| 3032 | angular.module('xos.helpers').factory('NoHyperlinks', noHyperlinks); |
| 3033 | |
| 3034 | function noHyperlinks() { |
| 3035 | return { |
| 3036 | request: function request(_request) { |
| 3037 | if (_request.url.indexOf('.html') === -1) { |
| 3038 | _request.url += '?no_hyperlinks=1'; |
| 3039 | } |
| 3040 | return _request; |
| 3041 | } |
| 3042 | }; |
| 3043 | } |
| 3044 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 3045 | //# sourceMappingURL=../maps/services/noHyperlinks.interceptor.js.map |
| 3046 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 3047 | 'use strict'; |
| 3048 | |
| 3049 | // TODO write tests for log |
| 3050 | |
| 3051 | /* eslint-disable angular/ng_window_service*/ |
| 3052 | |
| 3053 | angular.module('xos.helpers').config(['$provide', function ($provide) { |
| 3054 | // Use the `decorator` solution to substitute or attach behaviors to |
| 3055 | // original service instance; @see angular-mocks for more examples.... |
| 3056 | |
| 3057 | $provide.decorator('$log', ['$delegate', function ($delegate) { |
| 3058 | |
| 3059 | var isLogEnabled = function isLogEnabled() { |
| 3060 | return window.location.href.indexOf('debug=true') >= 0; |
| 3061 | }; |
| 3062 | // Save the original $log.debug() |
| 3063 | var logFn = $delegate.log; |
| 3064 | var infoFn = $delegate.info; |
| 3065 | var warnFn = $delegate.warn; |
| 3066 | //let errorFn = $delegate.error; |
| 3067 | var debugFn = $delegate.debug; |
| 3068 | |
| 3069 | // create the replacement function |
| 3070 | var replacement = function replacement(fn) { |
| 3071 | return function () { |
| 3072 | //console.log(`Is Log Enabled: ${isLogEnabled()}`) |
| 3073 | if (!isLogEnabled()) { |
| 3074 | // console.log('logging is disabled'); |
| 3075 | return; |
| 3076 | } |
| 3077 | |
| 3078 | var args = [].slice.call(arguments); |
| 3079 | var now = new Date(); |
| 3080 | |
| 3081 | // Prepend timestamp |
| 3082 | args[0] = '[' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds() + '] ' + args[0]; |
| 3083 | |
| 3084 | // HACK awfull fix for angular mock implementation whithin jasmine test failing issue |
| 3085 | if (angular.isFunction($delegate.reset) && !($delegate.debug.logs instanceof Array)) { |
| 3086 | // if we are within the mock and did not reset yet, we call it to avoid issue |
| 3087 | // console.log('mock log impl fix to avoid logs array not existing...'); |
| 3088 | $delegate.reset(); |
| 3089 | } |
| 3090 | |
| 3091 | // Call the original with the output prepended with formatted timestamp |
| 3092 | |
| 3093 | return fn.apply(null, args); |
| 3094 | }; |
| 3095 | }; |
| 3096 | |
| 3097 | $delegate.info = replacement(infoFn); |
| 3098 | $delegate.log = replacement(logFn); |
| 3099 | $delegate.warn = replacement(warnFn); |
| 3100 | //$delegate.error = replacement(errorFn); // note this will prevent errors to be printed |
| 3101 | $delegate.debug = replacement(debugFn); |
| 3102 | |
| 3103 | return $delegate; |
| 3104 | }]); |
| 3105 | }]); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 3106 | //# sourceMappingURL=../maps/services/log.decorator.js.map |
| 3107 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 3108 | 'use strict'; |
| 3109 | |
| 3110 | (function () { |
| 3111 | 'use strict'; |
| 3112 | |
| 3113 | /** |
| 3114 | * @ngdoc service |
| 3115 | * @name xos.helpers.SetCSRFToken |
| 3116 | * @description This factory is automatically loaded trough xos.helpers and will add an $http interceptor that will the CSRF-Token to your request headers |
| 3117 | **/ |
| 3118 | |
| 3119 | setCSRFToken.$inject = ["$cookies"]; |
| 3120 | angular.module('xos.helpers').factory('SetCSRFToken', setCSRFToken); |
| 3121 | |
| 3122 | function setCSRFToken($cookies) { |
| 3123 | return { |
| 3124 | request: function request(_request) { |
| 3125 | if (_request.method !== 'GET') { |
| 3126 | _request.headers['X-CSRFToken'] = $cookies.get('xoscsrftoken'); |
| 3127 | } |
| 3128 | return _request; |
| 3129 | } |
| 3130 | }; |
| 3131 | } |
| 3132 | })(); |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 3133 | //# sourceMappingURL=../maps/services/csrfToken.interceptor.js.map |
| 3134 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 3135 | /** |
| 3136 | * @ngdoc overview |
| 3137 | * @name ngXosLib |
| 3138 | * @id index |
| 3139 | * @description |
| 3140 | * # Welcome to the ngXosLib documentation! <br/> |
| 3141 | * This is the module that group all the helpers service and UI components for XOS. |
| 3142 | * <br/><br/> |
| 3143 | * You can find all the documentation related to the UI Component Library here: <a href="#/module/xos.uiComponents"> xos.uiComponents</a> <br/> |
| 3144 | * and the documentation related to all the other helpers here: <a href="#/module/xos.helpers"> xos.helpers</a> <br/> |
| 3145 | * ## Issues |
| 3146 | * Please report issues at https://jira.opencord.org |
| 3147 | **/ |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame^] | 3148 | "use strict"; |
| 3149 | //# sourceMappingURL=maps/index.ngdoc.js.map |