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 | |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 29 | angular.module('xos.uiComponents', ['chart.js', 'RecursionHelper', 'dndLists']); |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 30 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 31 | //# sourceMappingURL=../maps/ui_components/ui-components.module.js.map |
| 32 | |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 33 | 'use strict'; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 34 | |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 35 | /** |
| 36 | * © OpenCORD |
| 37 | * |
| 38 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 39 | * |
| 40 | * Created by teone on 3/24/16. |
| 41 | */ |
| 42 | |
| 43 | (function () { |
| 44 | 'use strict'; |
| 45 | |
| 46 | angular.module('xos.uiComponents') |
| 47 | |
| 48 | /** |
| 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); |
| 84 | }) |
| 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', { |
| 112 | restrict: 'E', |
| 113 | bindings: { |
| 114 | config: '=' |
| 115 | }, |
| 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 ', |
| 117 | bindToController: true, |
| 118 | controllerAs: 'vm', |
| 119 | controller: ["$injector", "LabelFormatter", "_", "XosFormHelpers", function controller($injector, LabelFormatter, _, XosFormHelpers) { |
| 120 | var _this = this; |
| 121 | |
| 122 | // TODO |
| 123 | // - Validate the config (what if resource does not exist?) |
| 124 | |
| 125 | // NOTE |
| 126 | // Corner case |
| 127 | // - if response is empty, how can we generate a form ? |
| 128 | |
| 129 | this.responseMsg = false; |
| 130 | this.responseErr = false; |
| 131 | |
| 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; |
| 153 | } |
| 154 | }], |
| 155 | classes: 'table table-striped table-bordered table-responsive', |
| 156 | filter: 'field', |
| 157 | order: true, |
| 158 | pagination: { |
| 159 | pageSize: 10 |
| 160 | } |
| 161 | }; |
| 162 | |
| 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 |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 238 | props.forEach(function (p) { |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 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 | }] |
| 250 | }); |
| 251 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 252 | //# sourceMappingURL=../../../maps/ui_components/smartComponents/smartTable/smartTable.component.js.map |
| 253 | |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -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 3/24/16. |
| 262 | */ |
| 263 | |
| 264 | (function () { |
| 265 | 'use strict'; |
| 266 | |
| 267 | angular.module('xos.uiComponents') |
| 268 | /** |
| 269 | * @ngdoc directive |
| 270 | * @name xos.uiComponents.directive:xosSmartPie |
| 271 | * @restrict E |
| 272 | * @description The xos-table directive |
| 273 | * @param {Object} config The configuration for the component, |
| 274 | * it is composed by the name of an angular [$resource](https://docs.angularjs.org/api/ngResource/service/$resource) |
| 275 | * and a field name that is used to group the data. |
| 276 | * ``` |
| 277 | * { |
| 278 | resource: 'Users', |
| 279 | groupBy: 'fieldName', |
| 280 | classes: 'my-custom-class', |
| 281 | labelFormatter: (labels) => { |
| 282 | // here you can format your label, |
| 283 | // you should return an array with the same order |
| 284 | return labels; |
| 285 | } |
| 286 | } |
| 287 | * ``` |
| 288 | * @scope |
| 289 | * @example |
| 290 | |
| 291 | Displaying Local data |
| 292 | <example module="sampleSmartPieLocal"> |
| 293 | <file name="index.html"> |
| 294 | <div ng-controller="SampleCtrlLocal as vm"> |
| 295 | <xos-smart-pie config="vm.configLocal"></xos-smart-pie> |
| 296 | </div> |
| 297 | </file> |
| 298 | <file name="script.js"> |
| 299 | angular.module('sampleSmartPieLocal', ['xos.uiComponents']) |
| 300 | .factory('_', function($window){ |
| 301 | return $window._; |
| 302 | }) |
| 303 | .controller('SampleCtrlLocal', function($timeout){ |
| 304 | |
| 305 | this.datas = [ |
| 306 | {id: 1, first_name: 'Jon', last_name: 'aaa', category: 2}, |
| 307 | {id: 2, first_name: 'Danaerys', last_name: 'Targaryen', category: 1}, |
| 308 | {id: 3, first_name: 'Aria', last_name: 'Stark', category: 2} |
| 309 | ]; |
| 310 | this.configLocal = { |
| 311 | data: [], |
| 312 | groupBy: 'category', |
| 313 | classes: 'local', |
| 314 | labelFormatter: (labels) => { |
| 315 | return labels.map(l => l === '1' ? 'North' : 'Dragon'); |
| 316 | } |
| 317 | }; |
| 318 | |
| 319 | $timeout(() => { |
| 320 | // this need to be triggered in this way just because of ngDoc, |
| 321 | // otherwise you can assign data directly in the config |
| 322 | this.configLocal.data = this.datas; |
| 323 | }, 1) |
| 324 | }); |
| 325 | </file> |
| 326 | </example> |
| 327 | Fetching data from API |
| 328 | <example module="sampleSmartPieResource"> |
| 329 | <file name="index.html"> |
| 330 | <div ng-controller="SampleCtrl as vm"> |
| 331 | <xos-smart-pie config="vm.config"></xos-smart-pie> |
| 332 | </div> |
| 333 | </file> |
| 334 | <file name="script.js"> |
| 335 | angular.module('sampleSmartPieResource', ['xos.uiComponents', 'ngResource', 'ngMockE2E']) |
| 336 | .controller('SampleCtrl', function(){ |
| 337 | this.config = { |
| 338 | resource: 'SampleResource', |
| 339 | groupBy: 'category', |
| 340 | classes: 'resource', |
| 341 | labelFormatter: (labels) => { |
| 342 | return labels.map(l => l === '1' ? 'North' : 'Dragon'); |
| 343 | } |
| 344 | }; |
| 345 | }); |
| 346 | </file> |
| 347 | <file name="backendPoll.js"> |
| 348 | angular.module('sampleSmartPieResource') |
| 349 | .run(function($httpBackend, _){ |
| 350 | let datas = [ |
| 351 | {id: 1, first_name: 'Jon', last_name: 'Snow', category: 1}, |
| 352 | {id: 2, first_name: 'Danaerys', last_name: 'Targaryen', category: 2}, |
| 353 | {id: 3, first_name: 'Aria', last_name: 'Stark', category: 1} |
| 354 | ]; |
| 355 | $httpBackend.whenGET('/test').respond(200, datas) |
| 356 | }) |
| 357 | .factory('_', function($window){ |
| 358 | return $window._; |
| 359 | }) |
| 360 | .service('SampleResource', function($resource){ |
| 361 | return $resource('/test/:id', {id: '@id'}); |
| 362 | }) |
| 363 | </file> |
| 364 | </example> |
| 365 | Polling data from API |
| 366 | <example module="sampleSmartPiePoll"> |
| 367 | <file name="index.html"> |
| 368 | <div ng-controller="SampleCtrl as vm"> |
| 369 | <xos-smart-pie config="vm.config"></xos-smart-pie> |
| 370 | </div> |
| 371 | </file> |
| 372 | <file name="script.js"> |
| 373 | angular.module('sampleSmartPiePoll', ['xos.uiComponents', 'ngResource', 'ngMockE2E']) |
| 374 | .controller('SampleCtrl', function(){ |
| 375 | this.config = { |
| 376 | resource: 'SampleResource', |
| 377 | groupBy: 'category', |
| 378 | poll: 2, |
| 379 | labelFormatter: (labels) => { |
| 380 | return labels.map(l => l === '1' ? 'Active' : 'Banned'); |
| 381 | } |
| 382 | }; |
| 383 | }); |
| 384 | </file> |
| 385 | <file name="backend.js"> |
| 386 | angular.module('sampleSmartPiePoll') |
| 387 | .run(function($httpBackend, _){ |
| 388 | let mock = [ |
| 389 | [ |
| 390 | {id: 1, first_name: 'Jon', last_name: 'Snow', category: 1}, |
| 391 | {id: 2, first_name: 'Danaerys', last_name: 'Targaryen', category: 2}, |
| 392 | {id: 3, first_name: 'Aria', last_name: 'Stark', category: 1}, |
| 393 | {id: 3, first_name: 'Tyrion', last_name: 'Lannister', category: 1} |
| 394 | ], |
| 395 | [ |
| 396 | {id: 1, first_name: 'Jon', last_name: 'Snow', category: 1}, |
| 397 | {id: 2, first_name: 'Danaerys', last_name: 'Targaryen', category: 2}, |
| 398 | {id: 3, first_name: 'Aria', last_name: 'Stark', category: 2}, |
| 399 | {id: 3, first_name: 'Tyrion', last_name: 'Lannister', category: 2} |
| 400 | ], |
| 401 | [ |
| 402 | {id: 1, first_name: 'Jon', last_name: 'Snow', category: 1}, |
| 403 | {id: 2, first_name: 'Danaerys', last_name: 'Targaryen', category: 2}, |
| 404 | {id: 3, first_name: 'Aria', last_name: 'Stark', category: 1}, |
| 405 | {id: 3, first_name: 'Tyrion', last_name: 'Lannister', category: 2} |
| 406 | ] |
| 407 | ]; |
| 408 | $httpBackend.whenGET('/test').respond(function(method, url, data, headers, params) { |
| 409 | return [200, mock[Math.round(Math.random() * 3)]]; |
| 410 | }); |
| 411 | }) |
| 412 | .factory('_', function($window){ |
| 413 | return $window._; |
| 414 | }) |
| 415 | .service('SampleResource', function($resource){ |
| 416 | return $resource('/test/:id', {id: '@id'}); |
| 417 | }) |
| 418 | </file> |
| 419 | </example> |
| 420 | */ |
| 421 | .component('xosSmartPie', { |
| 422 | restrict: 'E', |
| 423 | bindings: { |
| 424 | config: '=' |
| 425 | }, |
| 426 | 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 ', |
| 427 | bindToController: true, |
| 428 | controllerAs: 'vm', |
| 429 | controller: ["$injector", "$interval", "$scope", "$timeout", "_", function controller($injector, $interval, $scope, $timeout, _) { |
| 430 | var _this = this; |
| 431 | |
| 432 | if (!this.config.resource && !this.config.data) { |
| 433 | throw new Error('[xosSmartPie] Please provide a resource or an array of data in the configuration'); |
| 434 | } |
| 435 | |
| 436 | var groupData = function groupData(data) { |
| 437 | return _.groupBy(data, _this.config.groupBy); |
| 438 | }; |
| 439 | var formatData = function formatData(data) { |
| 440 | return _.reduce(Object.keys(data), function (list, group) { |
| 441 | return list.concat(data[group].length); |
| 442 | }, []); |
| 443 | }; |
| 444 | var formatLabels = function formatLabels(data) { |
| 445 | return angular.isFunction(_this.config.labelFormatter) ? _this.config.labelFormatter(Object.keys(data)) : Object.keys(data); |
| 446 | }; |
| 447 | |
| 448 | var prepareData = function prepareData(data) { |
| 449 | // group data |
| 450 | var grouped = groupData(data); |
| 451 | _this.data = formatData(grouped); |
| 452 | // create labels |
| 453 | _this.labels = formatLabels(grouped); |
| 454 | }; |
| 455 | |
| 456 | if (this.config.resource) { |
| 457 | (function () { |
| 458 | |
| 459 | _this.Resource = $injector.get(_this.config.resource); |
| 460 | var getData = function getData() { |
| 461 | _this.Resource.query().$promise.then(function (res) { |
| 462 | |
| 463 | if (!res[0]) { |
| 464 | return; |
| 465 | } |
| 466 | |
| 467 | prepareData(res); |
| 468 | }); |
| 469 | }; |
| 470 | |
| 471 | getData(); |
| 472 | |
| 473 | if (_this.config.poll) { |
| 474 | $interval(function () { |
| 475 | getData(); |
| 476 | }, _this.config.poll * 1000); |
| 477 | } |
| 478 | })(); |
| 479 | } else { |
| 480 | $scope.$watch(function () { |
| 481 | return _this.config.data; |
| 482 | }, function (data) { |
| 483 | if (data) { |
| 484 | prepareData(_this.config.data); |
| 485 | } |
| 486 | }, true); |
| 487 | } |
| 488 | |
| 489 | $scope.$on('create', function (event, chart) { |
| 490 | console.log('create: ' + chart.id); |
| 491 | }); |
| 492 | |
| 493 | $scope.$on('destroy', function (event, chart) { |
| 494 | console.log('destroy: ' + chart.id); |
| 495 | }); |
| 496 | }] |
| 497 | }); |
| 498 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 499 | //# sourceMappingURL=../../../maps/ui_components/smartComponents/smartPie/smartPie.component.js.map |
| 500 | |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame] | 501 | 'use strict'; |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 502 | |
| 503 | /** |
| 504 | * © OpenCORD |
| 505 | * |
| 506 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 507 | * |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 508 | * Created by teone on 4/15/16. |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 509 | */ |
| 510 | |
| 511 | (function () { |
| 512 | 'use strict'; |
| 513 | |
| 514 | angular.module('xos.uiComponents') |
| 515 | |
| 516 | /** |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 517 | * @ngdoc directive |
| 518 | * @name xos.uiComponents.directive:xosValidation |
| 519 | * @restrict E |
| 520 | * @description The xos-validation directive |
| 521 | * @param {Object} errors The error object |
| 522 | * @element ANY |
| 523 | * @scope |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 524 | * @example |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 525 | <example module="sampleValidation"> |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 526 | <file name="index.html"> |
| 527 | <div ng-controller="SampleCtrl as vm"> |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 528 | <div class="row"> |
| 529 | <div class="col-xs-12"> |
| 530 | <label>Set an error type:</label> |
| 531 | </div> |
| 532 | <div class="col-xs-2"> |
| 533 | <a class="btn" |
| 534 | ng-click="vm.field.$error.required = !vm.field.$error.required" |
| 535 | ng-class="{'btn-default': !vm.field.$error.required, 'btn-success': vm.field.$error.required}"> |
| 536 | Required |
| 537 | </a> |
| 538 | </div> |
| 539 | <div class="col-xs-2"> |
| 540 | <a class="btn" |
| 541 | ng-click="vm.field.$error.email = !vm.field.$error.email" |
| 542 | ng-class="{'btn-default': !vm.field.$error.email, 'btn-success': vm.field.$error.email}"> |
| 543 | Email |
| 544 | </a> |
| 545 | </div> |
| 546 | <div class="col-xs-2"> |
| 547 | <a class="btn" |
| 548 | ng-click="vm.field.$error.minlength = !vm.field.$error.minlength" |
| 549 | ng-class="{'btn-default': !vm.field.$error.minlength, 'btn-success': vm.field.$error.minlength}"> |
| 550 | Min Length |
| 551 | </a> |
| 552 | </div> |
| 553 | <div class="col-xs-2"> |
| 554 | <a class="btn" |
| 555 | ng-click="vm.field.$error.maxlength = !vm.field.$error.maxlength" |
| 556 | ng-class="{'btn-default': !vm.field.$error.maxlength, 'btn-success': vm.field.$error.maxlength}"> |
| 557 | Max Length |
| 558 | </a> |
| 559 | </div> |
| 560 | </div> |
| 561 | <xos-validation field ="vm.field" form = "vm.form"></xos-validation> |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 562 | </div> |
| 563 | </file> |
| 564 | <file name="script.js"> |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 565 | angular.module('sampleValidation', ['xos.uiComponents']) |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 566 | .controller('SampleCtrl', function(){ |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 567 | this.field = { |
| 568 | $error: {} |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 569 | }; |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 570 | this.form= { |
| 571 | $submitted:true |
| 572 | } |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 573 | }); |
| 574 | </file> |
| 575 | </example> |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 576 | */ |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 577 | |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 578 | .component('xosValidation', { |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 579 | restrict: 'E', |
| 580 | bindings: { |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 581 | field: '=', |
| 582 | form: '=' |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 583 | }, |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 584 | 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 ', |
| 585 | transclude: true, |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 586 | bindToController: true, |
| 587 | controllerAs: 'vm', |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 588 | controller: function controller() { |
| 589 | this.config = { |
| 590 | type: 'danger' |
| 591 | }; |
| 592 | } |
| 593 | }); |
| 594 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 595 | //# sourceMappingURL=../../../maps/ui_components/dumbComponents/validation/validation.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 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1027 | //# sourceMappingURL=../../../maps/ui_components/dumbComponents/table/table.component.js.map |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame] | 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 |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1094 | Autogenerated form |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1095 | <example module="sampleForm"> |
| 1096 | <file name="script.js"> |
| 1097 | angular.module('sampleForm', ['xos.uiComponents']) |
| 1098 | .factory('_', function($window){ |
| 1099 | return $window._; |
| 1100 | }) |
| 1101 | .controller('SampleCtrl', function(){ |
| 1102 | this.model = { |
| 1103 | first_name: 'Jhon', |
| 1104 | last_name: 'Doe', |
| 1105 | email: 'jhon.doe@sample.com', |
| 1106 | active: true, |
| 1107 | birthDate: '2015-02-17T22:06:38.059000Z' |
| 1108 | } |
| 1109 | this.config = { |
| 1110 | exclude: ['password', 'last_login'], |
| 1111 | formName: 'sampleForm', |
| 1112 | actions: [ |
| 1113 | { |
| 1114 | label: 'Save', |
| 1115 | icon: 'ok', // refers to bootstraps glyphicon |
| 1116 | cb: (user) => { // receive the model |
| 1117 | console.log(user); |
| 1118 | }, |
| 1119 | class: 'success' |
| 1120 | } |
| 1121 | ] |
| 1122 | }; |
| 1123 | }); |
| 1124 | </file> |
| 1125 | <file name="index.html"> |
| 1126 | <div ng-controller="SampleCtrl as vm"> |
| 1127 | <xos-form ng-model="vm.model" config="vm.config"></xos-form> |
| 1128 | </div> |
| 1129 | </file> |
| 1130 | </example> |
| 1131 | Configuration defined form |
| 1132 | <example module="sampleForm1"> |
| 1133 | <file name="script.js"> |
| 1134 | angular.module('sampleForm1', ['xos.uiComponents','ngResource', 'ngMockE2E']) |
| 1135 | .factory('_', function($window){ |
| 1136 | return $window._; |
| 1137 | }) |
| 1138 | .controller('SampleCtrl1', function(SampleResource){ |
| 1139 | this.model = { |
| 1140 | }; |
| 1141 | this.config = { |
| 1142 | exclude: ['password', 'last_login'], |
| 1143 | formName: 'sampleForm1', |
| 1144 | feedback: { |
| 1145 | show: false, |
| 1146 | message: 'Form submitted successfully !!!', |
| 1147 | type: 'success' |
| 1148 | }, |
| 1149 | actions: [ |
| 1150 | { |
| 1151 | label: 'Save', |
| 1152 | icon: 'ok', // refers to bootstraps glyphicon |
| 1153 | cb: (user) => { // receive the model |
| 1154 | console.log(user); |
| 1155 | this.config.feedback.show = true; |
| 1156 | this.config.feedback.type='success'; |
| 1157 | }, |
| 1158 | class: 'success' |
| 1159 | } |
| 1160 | ], |
| 1161 | fields: { |
| 1162 | first_name: { |
| 1163 | type: 'string', |
| 1164 | validators: { |
| 1165 | required: true |
| 1166 | } |
| 1167 | }, |
| 1168 | last_name: { |
| 1169 | label: 'Surname', |
| 1170 | type: 'string', |
| 1171 | validators: { |
| 1172 | required: true, |
| 1173 | minlength: 10 |
| 1174 | } |
| 1175 | }, |
| 1176 | age: { |
| 1177 | type: 'number', |
| 1178 | validators: { |
| 1179 | required: true, |
| 1180 | min: 21 |
| 1181 | } |
| 1182 | }, |
| 1183 | site: { |
| 1184 | label: 'Site', |
| 1185 | type: 'select', |
| 1186 | validators: { required: true}, |
| 1187 | hint: 'The Site this Slice belongs to', |
| 1188 | options: [] |
| 1189 | }, |
| 1190 | } |
| 1191 | }; |
| 1192 | SampleResource.query().$promise |
| 1193 | .then((users) => { |
| 1194 | //this.users_site = users; |
| 1195 | //console.log(users); |
| 1196 | this.optionVal = users; |
| 1197 | this.config.fields['site'].options = this.optionVal; |
| 1198 | //= this.optionVal; |
| 1199 | }) |
| 1200 | .catch((e) => { |
| 1201 | throw new Error(e); |
| 1202 | }); |
| 1203 | }); |
| 1204 | </file> |
| 1205 | <file name="backend.js"> |
| 1206 | angular.module('sampleForm1') |
| 1207 | .run(function($httpBackend, _){ |
| 1208 | let datas = [{id: 1, label: 'site1'},{id: 4, label: 'site4'},{id: 3, label: 'site3'}]; |
| 1209 | let paramsUrl = new RegExp(/\/test\/(.+)/); |
| 1210 | $httpBackend.whenGET('/test').respond(200, datas) |
| 1211 | }) |
| 1212 | .service('SampleResource', function($resource){ |
| 1213 | return $resource('/test/:id', {id: '@id'}); |
| 1214 | }); |
| 1215 | </file> |
| 1216 | <file name="index.html"> |
| 1217 | <div ng-controller="SampleCtrl1 as vm"> |
| 1218 | <xos-form ng-model="vm.model" config="vm.config"></xos-form> |
| 1219 | </div> |
| 1220 | </file> |
| 1221 | </example> |
| 1222 | **/ |
| 1223 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1224 | .component('xosForm', { |
| 1225 | restrict: 'E', |
| 1226 | bindings: { |
| 1227 | config: '=', |
| 1228 | ngModel: '=' |
| 1229 | }, |
| 1230 | 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 ', |
| 1231 | bindToController: true, |
| 1232 | controllerAs: 'vm', |
| 1233 | controller: ["$scope", "$log", "_", "XosFormHelpers", function controller($scope, $log, _, XosFormHelpers) { |
| 1234 | var _this = this; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1235 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1236 | if (!this.config) { |
| 1237 | throw new Error('[xosForm] Please provide a configuration via the "config" attribute'); |
| 1238 | } |
| 1239 | |
| 1240 | if (!this.config.actions) { |
| 1241 | throw new Error('[xosForm] Please provide an action list in the configuration'); |
| 1242 | } |
| 1243 | |
| 1244 | if (!this.config.feedback) { |
| 1245 | this.config.feedback = { |
| 1246 | show: false, |
| 1247 | message: 'Form submitted successfully !!!', |
| 1248 | type: 'success' |
| 1249 | }; |
| 1250 | } |
| 1251 | |
| 1252 | this.excludedField = ['id', 'validators', 'created', 'updated', 'deleted', 'backend_status']; |
| 1253 | if (this.config && this.config.exclude) { |
| 1254 | this.excludedField = this.excludedField.concat(this.config.exclude); |
| 1255 | } |
| 1256 | |
| 1257 | this.formField = []; |
| 1258 | |
| 1259 | $scope.$watch(function () { |
| 1260 | return _this.config; |
| 1261 | }, function () { |
| 1262 | if (!_this.ngModel) { |
| 1263 | return; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1264 | } |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1265 | var diff = _.difference(Object.keys(_this.ngModel), _this.excludedField); |
| 1266 | var modelField = XosFormHelpers.parseModelField(diff); |
| 1267 | _this.formField = XosFormHelpers.buildFormStructure(modelField, _this.config.fields, _this.ngModel); |
| 1268 | }, true); |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1269 | |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1270 | $scope.$watch(function () { |
| 1271 | return _this.ngModel; |
| 1272 | }, function (model) { |
| 1273 | // empty from old stuff |
| 1274 | _this.formField = {}; |
| 1275 | if (!model) { |
| 1276 | return; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1277 | } |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1278 | var diff = _.difference(Object.keys(model), _this.excludedField); |
| 1279 | var modelField = XosFormHelpers.parseModelField(diff); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1280 | _this.formField = XosFormHelpers.buildFormStructure(modelField, _this.config.fields, model, _this.config.order); |
Arpit Agarwal | 34b6383 | 2016-08-08 11:59:45 -0700 | [diff] [blame] | 1281 | }); |
| 1282 | }] |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1283 | }); |
| 1284 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1285 | //# sourceMappingURL=../../../maps/ui_components/dumbComponents/form/form.component.js.map |
| 1286 | |
| 1287 | 'use strict'; |
| 1288 | |
| 1289 | /** |
| 1290 | * © OpenCORD |
| 1291 | * |
| 1292 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 1293 | * |
| 1294 | * Created by teone on 4/15/16. |
| 1295 | */ |
| 1296 | |
| 1297 | (function () { |
| 1298 | 'use strict'; |
| 1299 | |
| 1300 | angular.module('xos.uiComponents') |
| 1301 | |
| 1302 | /** |
| 1303 | * @ngdoc directive |
| 1304 | * @name xos.uiComponents.directive:xosPagination |
| 1305 | * @restrict E |
| 1306 | * @description The xos-table directive |
| 1307 | * @param {Number} pageSize Number of elements per page |
| 1308 | * @param {Number} totalElements Number of total elements in the collection |
| 1309 | * @param {Function} change The callback to be triggered on page change. |
| 1310 | * * @element ANY |
| 1311 | * @scope |
| 1312 | * @example |
| 1313 | <example module="samplePagination"> |
| 1314 | <file name="index.html"> |
| 1315 | <div ng-controller="SampleCtrl1 as vm"> |
| 1316 | <xos-pagination |
| 1317 | page-size="vm.pageSize" |
| 1318 | total-elements="vm.totalElements" |
| 1319 | change="vm.change"> |
| 1320 | </xos-pagination> |
| 1321 | </div> |
| 1322 | </file> |
| 1323 | <file name="script.js"> |
| 1324 | angular.module('samplePagination', ['xos.uiComponents']) |
| 1325 | .controller('SampleCtrl1', function(){ |
| 1326 | this.pageSize = 10; |
| 1327 | this.totalElements = 35; |
| 1328 | this.change = (pageNumber) => { |
| 1329 | console.log(pageNumber); |
| 1330 | } |
| 1331 | }); |
| 1332 | </file> |
| 1333 | </example> |
| 1334 | **/ |
| 1335 | |
| 1336 | .component('xosPagination', { |
| 1337 | restrict: 'E', |
| 1338 | bindings: { |
| 1339 | pageSize: '=', |
| 1340 | totalElements: '=', |
| 1341 | change: '=' |
| 1342 | }, |
| 1343 | 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 ', |
| 1344 | bindToController: true, |
| 1345 | controllerAs: 'vm', |
| 1346 | controller: ["$scope", function controller($scope) { |
| 1347 | var _this = this; |
| 1348 | |
| 1349 | this.currentPage = 0; |
| 1350 | |
| 1351 | this.goToPage = function (n) { |
| 1352 | if (n < 0 || n === _this.pages) { |
| 1353 | return; |
| 1354 | } |
| 1355 | _this.currentPage = n; |
| 1356 | _this.change(n); |
| 1357 | }; |
| 1358 | |
| 1359 | this.createPages = function (pages) { |
| 1360 | var arr = []; |
| 1361 | for (var i = 0; i < pages; i++) { |
| 1362 | arr.push(i); |
| 1363 | } |
| 1364 | return arr; |
| 1365 | }; |
| 1366 | |
| 1367 | // watch for data changes |
| 1368 | $scope.$watch(function () { |
| 1369 | return _this.totalElements; |
| 1370 | }, function () { |
| 1371 | if (_this.totalElements) { |
| 1372 | _this.pages = Math.ceil(_this.totalElements / _this.pageSize); |
| 1373 | _this.pageList = _this.createPages(_this.pages); |
| 1374 | } |
| 1375 | }); |
| 1376 | }] |
| 1377 | }).filter('pagination', function () { |
| 1378 | return function (input, start) { |
| 1379 | if (!input || !angular.isArray(input)) { |
| 1380 | return input; |
| 1381 | } |
| 1382 | start = parseInt(start, 10); |
| 1383 | return input.slice(start); |
| 1384 | }; |
| 1385 | }); |
| 1386 | })(); |
| 1387 | //# sourceMappingURL=../../../maps/ui_components/dumbComponents/pagination/pagination.component.js.map |
| 1388 | |
Arpit Agarwal | 4397874 | 2016-08-09 15:38:25 -0700 | [diff] [blame] | 1389 | 'use strict'; |
| 1390 | |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1391 | 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); } } |
| 1392 | |
| 1393 | /** |
| 1394 | * © OpenCORD |
| 1395 | * |
| 1396 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 1397 | * |
| 1398 | * Created by teone on 5/25/16. |
| 1399 | */ |
| 1400 | |
| 1401 | (function () { |
| 1402 | 'use strict'; |
| 1403 | |
| 1404 | angular.module('xos.uiComponents') |
| 1405 | /** |
| 1406 | * @ngdoc directive |
| 1407 | * @name xos.uiComponents.directive:xosField |
| 1408 | * @restrict E |
| 1409 | * @description The xos-field directive. |
| 1410 | * This component decide, give a field wich kind of input it need to print. |
| 1411 | * @param {string} name The field name |
| 1412 | * @param {object} field The field configuration: |
| 1413 | * ``` |
| 1414 | * { |
| 1415 | * label: 'Label', |
| 1416 | * type: 'number', //typeof field |
| 1417 | * validators: {} // see xosForm for more details |
| 1418 | * } |
| 1419 | * ``` |
| 1420 | * @param {mixed} ngModel The field value |
| 1421 | * |
| 1422 | * @example |
| 1423 | |
| 1424 | # Basic Example |
| 1425 | |
| 1426 | <example module="sampleField1"> |
| 1427 | <file name="script.js"> |
| 1428 | angular.module('sampleField1', ['xos.uiComponents']) |
| 1429 | .factory('_', function($window){ |
| 1430 | return $window._; |
| 1431 | }) |
| 1432 | .controller('SampleCtrl', function(){ |
| 1433 | this.name = 'input-name'; |
| 1434 | this.field = {label: 'My String Value:', type: 'string'}; |
| 1435 | this.model = 'my string'; |
| 1436 | }); |
| 1437 | </file> |
| 1438 | <file name="index.html"> |
| 1439 | <div ng-controller="SampleCtrl as vm"> |
| 1440 | <xos-field ng-model="vm.model" name="vm.name" field="vm.field"></xos-field> |
| 1441 | </div> |
| 1442 | </file> |
| 1443 | </example> |
| 1444 | |
| 1445 | # Possible Values |
| 1446 | <example module="sampleField2"> |
| 1447 | <file name="script.js"> |
| 1448 | angular.module('sampleField2', ['xos.uiComponents']) |
| 1449 | .factory('_', function($window){ |
| 1450 | return $window._; |
| 1451 | }) |
| 1452 | .controller('SampleCtrl', function(){ |
| 1453 | this.field1 = { |
| 1454 | name: 'number-field', |
| 1455 | field: {label: 'My Number Value:', type: 'number'}, |
| 1456 | model: 2 |
| 1457 | }; |
| 1458 | this.field2 = { |
| 1459 | name: 'date-field', |
| 1460 | field: {label: 'My Date Value:', type: 'date'}, |
| 1461 | model: new Date() |
| 1462 | }; |
| 1463 | this.field3 = { |
| 1464 | name: 'boolean-field', |
| 1465 | field: {label: 'My Boolean Value:', type: 'boolean'}, |
| 1466 | model: true |
| 1467 | }; |
| 1468 | this.field4 = { |
| 1469 | name: 'email-field', |
| 1470 | field: {label: 'My Email Value:', type: 'email'}, |
| 1471 | model: 'sample@domain.us' |
| 1472 | }; |
| 1473 | this.field5 = { |
| 1474 | name: 'select', |
| 1475 | label: 'Select field:', |
| 1476 | type: 'select', |
| 1477 | model: 1, |
| 1478 | options: [ |
| 1479 | {id: 1, label: 'One'}, |
| 1480 | {id: 2, label: 'Two'}, |
| 1481 | {id: 3, label: 'Three'}, |
| 1482 | ] |
| 1483 | }; |
| 1484 | }); |
| 1485 | </file> |
| 1486 | <file name="index.html"> |
| 1487 | <div ng-controller="SampleCtrl as vm"> |
| 1488 | <xos-field ng-model="vm.field1.model" name="vm.field1.name" field="vm.field1.field"></xos-field> |
| 1489 | <xos-field ng-model="vm.field2.model" name="vm.field2.name" field="vm.field2.field"></xos-field> |
| 1490 | <xos-field ng-model="vm.field3.model" name="vm.field3.name" field="vm.field3.field"></xos-field> |
| 1491 | <xos-field ng-model="vm.field4.model" name="vm.field4.name" field="vm.field4.field"></xos-field> |
| 1492 | <xos-field ng-model="vm.field5.model" name="vm.field5.name" field="vm.field5.field"></xos-field> |
| 1493 | </div> |
| 1494 | </file> |
| 1495 | </example> |
| 1496 | # This element is recursive |
| 1497 | <example module="sampleField3"> |
| 1498 | <file name="script.js"> |
| 1499 | angular.module('sampleField3', ['xos.uiComponents']) |
| 1500 | .factory('_', function($window){ |
| 1501 | return $window._; |
| 1502 | }) |
| 1503 | .controller('SampleCtrl', function(){ |
| 1504 | this.name1 = 'input-name'; |
| 1505 | this.field1 = {label: 'My Object Field:', type: 'object'}; |
| 1506 | this.model1 = { |
| 1507 | name: 'Jhon', |
| 1508 | age: '25', |
| 1509 | email: 'jhon@thewall.ru', |
| 1510 | active: true |
| 1511 | }; |
| 1512 | this.name2 = 'another-name'; |
| 1513 | this.field2 = { |
| 1514 | label: 'Empty Object Field', |
| 1515 | type: 'object', |
| 1516 | properties: { |
| 1517 | foo: { |
| 1518 | label: 'FooLabel:', |
| 1519 | type: 'string', |
| 1520 | validators: { |
| 1521 | required: true |
| 1522 | } |
| 1523 | }, |
| 1524 | bar: { |
| 1525 | type: 'number' |
| 1526 | } |
| 1527 | } |
| 1528 | } |
| 1529 | }); |
| 1530 | </file> |
| 1531 | <file name="index.html"> |
| 1532 | <div ng-controller="SampleCtrl as vm"> |
| 1533 | <h4>Autogenerated object field</h4> |
| 1534 | <xos-field ng-model="vm.model1" name="vm.name1" field="vm.field1"></xos-field> |
| 1535 | <h4>Configured object field</h4> |
| 1536 | <xos-field ng-model="vm.model2" name="vm.name2" field="vm.field2"></xos-field> |
| 1537 | </div> |
| 1538 | </file> |
| 1539 | </example> |
| 1540 | */ |
| 1541 | .component('xosField', { |
| 1542 | restrict: 'E', |
| 1543 | bindings: { |
| 1544 | name: '=', |
| 1545 | field: '=', |
| 1546 | ngModel: '=' |
| 1547 | }, |
| 1548 | template: '\n <label ng-if="vm.field.type !== \'object\' && vm.field.type !== \'array\'">{{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\' && vm.field.type !== \'array\'"\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 <div\n class="panel panel-default array-field"\n ng-if="vm.field.type == \'array\'">\n <div class="panel-heading">{{vm.field.label}}</div>\n <div class="panel-body selected">\n <ul class="draggable" dnd-list="vm.ngModel">\n <li\n class="array-element"\n ng-repeat="item in vm.ngModel"\n dnd-draggable="item"\n dnd-moved="vm.ngModel.splice($index, 1)"\n dnd-effect-allowed="move"\n dnd-selected="models.selected = item"\n >\n <div class="well well-sm text-center">\n {{item}}\n </div>\n </li>\n <div class="clearfix"></div>\n </ul>\n </div>\n <div class="panel-body unselected">\n <ul class="draggable" dnd-list="vm.field.availableOptions">\n <li\n class="array-element"\n ng-repeat="item in vm.field.availableOptions"\n dnd-draggable="item"\n dnd-moved="vm.field.availableOptions.splice($index, 1)"\n dnd-effect-allowed="move"\n dnd-selected="models.selected = item"\n >\n <div class="well well-sm text-center">\n {{item}}\n </div>\n </li>\n <div class="clearfix"></div>\n </ul>\n </div>\n </div>\n ', |
| 1549 | bindToController: true, |
| 1550 | controllerAs: 'vm', |
| 1551 | controller: ["$attrs", "$scope", "XosFormHelpers", "LabelFormatter", "_", function controller($attrs, $scope, XosFormHelpers, LabelFormatter, _) { |
| 1552 | var _this = this; |
| 1553 | |
| 1554 | if (!this.name) { |
| 1555 | throw new Error('[xosField] Please provide a field name'); |
| 1556 | } |
| 1557 | if (!this.field) { |
| 1558 | throw new Error('[xosField] Please provide a field definition'); |
| 1559 | } |
| 1560 | if (!this.field.type) { |
| 1561 | throw new Error('[xosField] Please provide a type in the field definition'); |
| 1562 | } |
| 1563 | if (!$attrs.ngModel) { |
| 1564 | throw new Error('[xosField] Please provide an ng-model'); |
| 1565 | } |
| 1566 | this.getType = XosFormHelpers._getFieldFormat; |
| 1567 | this.formatLabel = LabelFormatter.format; |
| 1568 | |
| 1569 | this.isEmptyObject = function (o) { |
| 1570 | return o ? Object.keys(o).length === 0 : true; |
| 1571 | }; |
| 1572 | |
| 1573 | if (this.field.type === 'array') { |
| 1574 | $scope.$watch(function () { |
| 1575 | return _this.ngModel.length; |
| 1576 | }, function () { |
| 1577 | _this.field.availableOptions = _.difference(_this.field.options, _this.ngModel); |
| 1578 | }); |
| 1579 | } |
| 1580 | }] |
| 1581 | }) |
| 1582 | |
| 1583 | /** |
| 1584 | * @ngdoc directive |
| 1585 | * @name xos.uiComponents.directive:xosCustomValidator |
| 1586 | * @restrict A |
| 1587 | * @description The xosCustomValidator directive. |
| 1588 | * This component apply a custom validation function |
| 1589 | * @param {function} customValidator The function that execute the validation. |
| 1590 | * |
| 1591 | * You should do your validation here and return true | false, |
| 1592 | * or alternatively you can return an array [errorName, true|false] |
| 1593 | */ |
| 1594 | .directive('xosCustomValidator', function () { |
| 1595 | return { |
| 1596 | restrict: 'A', |
| 1597 | scope: { |
| 1598 | fn: '=customValidator' |
| 1599 | }, |
| 1600 | require: 'ngModel', |
| 1601 | link: function link(scope, element, attr, ctrl) { |
| 1602 | if (!angular.isFunction(scope.fn)) { |
| 1603 | return; |
| 1604 | } |
| 1605 | |
| 1606 | function customValidatorWrapper(ngModelValue) { |
| 1607 | var valid = scope.fn(ngModelValue); |
| 1608 | if (angular.isArray(valid)) { |
| 1609 | // ES6 spread rocks over fn.apply() |
| 1610 | ctrl.$setValidity.apply(ctrl, _toConsumableArray(valid)); |
| 1611 | } else { |
| 1612 | ctrl.$setValidity('custom', valid); |
| 1613 | } |
| 1614 | return ngModelValue; |
| 1615 | } |
| 1616 | |
| 1617 | ctrl.$parsers.push(customValidatorWrapper); |
| 1618 | } |
| 1619 | }; |
| 1620 | }); |
| 1621 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1622 | //# sourceMappingURL=../../../maps/ui_components/dumbComponents/field/field.component.js.map |
| 1623 | |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1624 | 'use strict'; |
| 1625 | |
| 1626 | /** |
| 1627 | * © OpenCORD |
| 1628 | * |
| 1629 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 1630 | * |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 1631 | * Created by teone on 4/15/16. |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1632 | */ |
| 1633 | |
| 1634 | (function () { |
| 1635 | 'use strict'; |
| 1636 | |
| 1637 | angular.module('xos.uiComponents') |
| 1638 | |
| 1639 | /** |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 1640 | * @ngdoc directive |
| 1641 | * @name xos.uiComponents.directive:xosAlert |
| 1642 | * @restrict E |
| 1643 | * @description The xos-alert directive |
| 1644 | * @param {Object} config The configuration object |
| 1645 | * ``` |
| 1646 | * { |
| 1647 | * type: 'danger', //info, success, warning |
| 1648 | * closeBtn: true, //default false |
| 1649 | * autoHide: 3000 //delay to automatically hide the alert |
| 1650 | * } |
| 1651 | * ``` |
| 1652 | * @param {Boolean=} show Binding to show and hide the alert, default to true |
| 1653 | * @element ANY |
| 1654 | * @scope |
| 1655 | * @example |
| 1656 | <example module="sampleAlert1"> |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1657 | <file name="index.html"> |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 1658 | <div ng-controller="SampleCtrl1 as vm"> |
| 1659 | <xos-alert config="vm.config1"> |
| 1660 | A sample alert message |
| 1661 | </xos-alert> |
| 1662 | <xos-alert config="vm.config2"> |
| 1663 | A sample alert message (with close button) |
| 1664 | </xos-alert> |
| 1665 | <xos-alert config="vm.config3"> |
| 1666 | A sample info message |
| 1667 | </xos-alert> |
| 1668 | <xos-alert config="vm.config4"> |
| 1669 | A sample success message |
| 1670 | </xos-alert> |
| 1671 | <xos-alert config="vm.config5"> |
| 1672 | A sample warning message |
| 1673 | </xos-alert> |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1674 | </div> |
| 1675 | </file> |
| 1676 | <file name="script.js"> |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 1677 | angular.module('sampleAlert1', ['xos.uiComponents']) |
| 1678 | .controller('SampleCtrl1', function(){ |
| 1679 | this.config1 = { |
| 1680 | type: 'danger' |
| 1681 | }; |
| 1682 | this.config2 = { |
| 1683 | type: 'danger', |
| 1684 | closeBtn: true |
| 1685 | }; |
| 1686 | this.config3 = { |
| 1687 | type: 'info' |
| 1688 | }; |
| 1689 | this.config4 = { |
| 1690 | type: 'success' |
| 1691 | }; |
| 1692 | this.config5 = { |
| 1693 | type: 'warning' |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1694 | }; |
| 1695 | }); |
| 1696 | </file> |
| 1697 | </example> |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 1698 | <example module="sampleAlert2" animations="true"> |
| 1699 | <file name="index.html"> |
| 1700 | <div ng-controller="SampleCtrl as vm" class="row"> |
| 1701 | <div class="col-sm-4"> |
| 1702 | <a class="btn btn-default btn-block" ng-show="!vm.show" ng-click="vm.show = true">Show Alert</a> |
| 1703 | <a class="btn btn-default btn-block" ng-show="vm.show" ng-click="vm.show = false">Hide Alert</a> |
| 1704 | </div> |
| 1705 | <div class="col-sm-8"> |
| 1706 | <xos-alert config="vm.config1" show="vm.show"> |
| 1707 | A sample alert message, not displayed by default. |
| 1708 | </xos-alert> |
| 1709 | </div> |
| 1710 | </div> |
| 1711 | </file> |
| 1712 | <file name="script.js"> |
| 1713 | angular.module('sampleAlert2', ['xos.uiComponents', 'ngAnimate']) |
| 1714 | .controller('SampleCtrl', function(){ |
| 1715 | this.config1 = { |
| 1716 | type: 'success' |
| 1717 | }; |
| 1718 | this.show = false; |
| 1719 | }); |
| 1720 | </file> |
| 1721 | </example> |
| 1722 | **/ |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1723 | |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 1724 | .component('xosAlert', { |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1725 | restrict: 'E', |
| 1726 | bindings: { |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 1727 | config: '=', |
| 1728 | show: '=?' |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1729 | }, |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 1730 | 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 ', |
| 1731 | transclude: true, |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1732 | bindToController: true, |
| 1733 | controllerAs: 'vm', |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 1734 | controller: ["$timeout", function controller($timeout) { |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1735 | var _this = this; |
| 1736 | |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 1737 | if (!this.config) { |
| 1738 | throw new Error('[xosAlert] Please provide a configuration via the "config" attribute'); |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 1741 | // default the value to true |
| 1742 | this.show = this.show !== false; |
| 1743 | |
| 1744 | this.dismiss = function () { |
| 1745 | _this.show = false; |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1746 | }; |
| 1747 | |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 1748 | if (this.config.autoHide) { |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1749 | (function () { |
Matteo Scandolo | 1d68985 | 2016-09-29 09:42:12 -0700 | [diff] [blame] | 1750 | var to = $timeout(function () { |
| 1751 | _this.dismiss(); |
| 1752 | $timeout.cancel(to); |
| 1753 | }, _this.config.autoHide); |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1754 | })(); |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1755 | } |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1756 | }] |
| 1757 | }); |
| 1758 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1759 | //# sourceMappingURL=../../../maps/ui_components/dumbComponents/alert/alert.component.js.map |
| 1760 | |
Matteo Scandolo | 65116c4 | 2016-09-21 17:06:23 -0700 | [diff] [blame] | 1761 | 'use strict'; |
| 1762 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1763 | (function () { |
| 1764 | 'use strict'; |
| 1765 | |
| 1766 | /** |
| 1767 | * @ngdoc service |
| 1768 | * @name xos.uiComponents.LabelFormatter |
| 1769 | * @description This factory define a set of helper function to format label started from an object property |
| 1770 | **/ |
| 1771 | |
| 1772 | angular.module('xos.uiComponents').factory('LabelFormatter', labelFormatter); |
| 1773 | |
| 1774 | function labelFormatter() { |
| 1775 | |
| 1776 | /** |
| 1777 | * @ngdoc method |
| 1778 | * @name xos.uiComponents.LabelFormatter#_formatByUnderscore |
| 1779 | * @methodOf xos.uiComponents.LabelFormatter |
| 1780 | * @description |
| 1781 | * Convert a `snake_case` string to readable string.<br/> |
| 1782 | * Eg: `this_string` will became `this string` |
| 1783 | * @param {string} string The string to be converted |
| 1784 | * @returns {string} The converten string |
| 1785 | **/ |
| 1786 | |
| 1787 | var _formatByUnderscore = function _formatByUnderscore(string) { |
| 1788 | return string.split('_').join(' ').trim(); |
| 1789 | }; |
| 1790 | |
| 1791 | /** |
| 1792 | * @ngdoc method |
| 1793 | * @name xos.uiComponents.LabelFormatter#_formatByUppercase |
| 1794 | * @methodOf xos.uiComponents.LabelFormatter |
| 1795 | * @description |
| 1796 | * Convert a `camelCase` string to readable string.<br/> |
| 1797 | * Eg: `thisString` will became `this string` |
| 1798 | * @param {string} string The string to be converted |
| 1799 | * @returns {string} The converten string |
| 1800 | **/ |
| 1801 | |
| 1802 | var _formatByUppercase = function _formatByUppercase(string) { |
| 1803 | return string.split(/(?=[A-Z])/).map(function (w) { |
| 1804 | return w.toLowerCase(); |
| 1805 | }).join(' '); |
| 1806 | }; |
| 1807 | |
| 1808 | /** |
| 1809 | * @ngdoc method |
| 1810 | * @name xos.uiComponents.LabelFormatter#_capitalize |
| 1811 | * @methodOf xos.uiComponents.LabelFormatter |
| 1812 | * @description |
| 1813 | * Capitalize the first letter of a string.<br/> |
| 1814 | * Eg: `this string` will became `This string` |
| 1815 | * @param {string} string The string to be converted |
| 1816 | * @returns {string} The converten string |
| 1817 | **/ |
| 1818 | |
| 1819 | var _capitalize = function _capitalize(string) { |
| 1820 | return string.slice(0, 1).toUpperCase() + string.slice(1); |
| 1821 | }; |
| 1822 | |
| 1823 | /** |
| 1824 | * @ngdoc method |
| 1825 | * @name xos.uiComponents.LabelFormatter#format |
| 1826 | * @methodOf xos.uiComponents.LabelFormatter |
| 1827 | * @description |
| 1828 | * Apply in order: |
| 1829 | * - _formatByUnderscore |
| 1830 | * - _formatByUppercase |
| 1831 | * - _capitalize |
| 1832 | * - replace multiple space with a single one |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1833 | * - append `:` at the end |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1834 | * <br/> |
| 1835 | * Eg: `this_string` will became `This string:`<br/> |
| 1836 | * Eg: `thisString` will became `This string:` |
| 1837 | * @param {string} string The string to be converted |
| 1838 | * @returns {string} The converten string |
| 1839 | **/ |
| 1840 | |
| 1841 | var format = function format(string) { |
| 1842 | string = _formatByUnderscore(string); |
| 1843 | string = _formatByUppercase(string); |
| 1844 | |
| 1845 | string = _capitalize(string).replace(/\s\s+/g, ' ') + ':'; |
| 1846 | return string.replace('::', ':'); |
| 1847 | }; |
| 1848 | |
| 1849 | return { |
| 1850 | // test export |
| 1851 | _formatByUnderscore: _formatByUnderscore, |
| 1852 | _formatByUppercase: _formatByUppercase, |
| 1853 | _capitalize: _capitalize, |
| 1854 | // export to use |
| 1855 | format: format |
| 1856 | }; |
| 1857 | } |
| 1858 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1859 | //# sourceMappingURL=../../../maps/services/helpers/ui/label_formatter.service.js.map |
| 1860 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1861 | 'use strict'; |
| 1862 | |
| 1863 | 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; }; |
| 1864 | |
| 1865 | (function () { |
| 1866 | |
| 1867 | angular.module('xos.uiComponents') |
| 1868 | |
| 1869 | /** |
| 1870 | * @ngdoc service |
| 1871 | * @name xos.uiComponents.XosFormHelpers |
| 1872 | * @requires xos.uiComponents.LabelFormatter |
| 1873 | * @requires xos.helpers._ |
| 1874 | **/ |
| 1875 | |
| 1876 | .service('XosFormHelpers', ["_", "LabelFormatter", function (_, LabelFormatter) { |
| 1877 | var _this = this; |
| 1878 | |
| 1879 | /** |
| 1880 | * @ngdoc method |
| 1881 | * @name xos.uiComponents.XosFormHelpers#_isEmail |
| 1882 | * @methodOf xos.uiComponents.XosFormHelpers |
| 1883 | * @description |
| 1884 | * Return true if the string is an email address |
| 1885 | * @param {string} text The string to be evaluated |
| 1886 | * @returns {boolean} If the string match an email format |
| 1887 | **/ |
| 1888 | |
| 1889 | this._isEmail = function (text) { |
| 1890 | 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,}))/; |
| 1891 | return re.test(text); |
| 1892 | }; |
| 1893 | |
| 1894 | /** |
| 1895 | * @ngdoc method |
| 1896 | * @name xos.uiComponents.XosFormHelpers#_getFieldFormat |
| 1897 | * @methodOf xos.uiComponents.XosFormHelpers |
| 1898 | * @description |
| 1899 | * Return the type of the input |
| 1900 | * @param {mixed} value The data to be evaluated |
| 1901 | * @returns {string} The type of the input |
| 1902 | **/ |
| 1903 | |
| 1904 | this._getFieldFormat = function (value) { |
| 1905 | |
| 1906 | if (angular.isArray(value)) { |
| 1907 | return 'array'; |
| 1908 | } |
| 1909 | |
| 1910 | // check if is date |
Matteo Scandolo | e57712f | 2016-09-21 15:27:36 -0700 | [diff] [blame] | 1911 | if (angular.isDate(value) || !Number.isNaN(Date.parse(value)) && // Date.parse is a number |
| 1912 | /^\d+-\d+-\d+\D\d+:\d+:\d+\.\d+\D/.test(value) // the format match ISO dates |
| 1913 | ) { |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1914 | return 'date'; |
| 1915 | } |
| 1916 | |
| 1917 | // check if is boolean |
| 1918 | // isNaN(false) = false, false is a number (0), true is a number (1) |
| 1919 | if (typeof value === 'boolean') { |
| 1920 | return 'boolean'; |
| 1921 | } |
| 1922 | |
| 1923 | // check if a string is an email |
| 1924 | if (_this._isEmail(value)) { |
| 1925 | return 'email'; |
| 1926 | } |
| 1927 | |
| 1928 | // if null return string |
| 1929 | if (angular.isString(value) || value === null) { |
| 1930 | return 'text'; |
| 1931 | } |
| 1932 | |
| 1933 | return typeof value === 'undefined' ? 'undefined' : _typeof(value); |
| 1934 | }; |
| 1935 | |
| 1936 | /** |
| 1937 | * @ngdoc method |
| 1938 | * @name xos.uiComponents.XosFormHelpers#buildFormStructure |
| 1939 | * @methodOf xos.uiComponents.XosFormHelpers |
| 1940 | * @description |
| 1941 | * Return the type of the input |
| 1942 | * @param {object} modelField An object containing one property for each field of the model |
| 1943 | * @param {object} customField An object containing one property for each field custom field |
| 1944 | * @param {object} model The actual model on wich build the form structure (it is used to determine the type of the input) |
| 1945 | * @returns {object} An object describing the form structure in the form of: |
| 1946 | * ``` |
| 1947 | * { |
| 1948 | * 'field-name': { |
| 1949 | * label: 'Label', |
| 1950 | * type: 'number', //typeof field |
| 1951 | * validators: {}, // see xosForm for more details |
| 1952 | * hint: 'A Custom hint for the field' |
| 1953 | * } |
| 1954 | * } |
| 1955 | * ``` |
| 1956 | **/ |
| 1957 | |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1958 | this.buildFormStructure = function (modelField, customField, model, order) { |
| 1959 | |
| 1960 | var orderedForm = {}; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1961 | |
| 1962 | modelField = angular.extend(modelField, customField); |
| 1963 | customField = customField || {}; |
| 1964 | |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1965 | if (order) { |
| 1966 | _.each(order, function (key) { |
| 1967 | orderedForm[key] = {}; |
| 1968 | }); |
| 1969 | } |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1970 | |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1971 | _.each(Object.keys(modelField), function (f) { |
| 1972 | |
| 1973 | orderedForm[f] = { |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1974 | label: customField[f] && customField[f].label ? customField[f].label + ':' : LabelFormatter.format(f), |
| 1975 | type: customField[f] && customField[f].type ? customField[f].type : _this._getFieldFormat(model[f]), |
| 1976 | validators: customField[f] && customField[f].validators ? customField[f].validators : {}, |
| 1977 | hint: customField[f] && customField[f].hint ? customField[f].hint : '' |
| 1978 | }; |
| 1979 | |
| 1980 | if (customField[f] && customField[f].options) { |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1981 | orderedForm[f].options = customField[f].options; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1982 | } |
| 1983 | if (customField[f] && customField[f].properties) { |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1984 | orderedForm[f].properties = customField[f].properties; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1985 | } |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1986 | if (orderedForm[f].type === 'date') { |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1987 | model[f] = new Date(model[f]); |
| 1988 | } |
| 1989 | |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1990 | if (orderedForm[f].type === 'number') { |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1991 | model[f] = parseInt(model[f], 10); |
| 1992 | } |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1993 | }); |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1994 | |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 1995 | return orderedForm; |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 1996 | }; |
| 1997 | |
| 1998 | /** |
| 1999 | * @ngdoc method |
| 2000 | * @name xos.uiComponents.XosFormHelpers#parseModelField |
| 2001 | * @methodOf xos.uiComponents.XosFormHelpers |
| 2002 | * @description |
| 2003 | * Helpers for buildFormStructure, convert a list of model properties in an object used to build the form structure, eg: |
| 2004 | * ``` |
| 2005 | * // input: |
| 2006 | * ['id', 'name'm 'mail'] |
| 2007 | * |
| 2008 | * // output |
| 2009 | * { |
| 2010 | * id: {}, |
| 2011 | * name: {}, |
| 2012 | * mail: {} |
| 2013 | * } |
| 2014 | * ``` |
| 2015 | * @param {array} fields An array of fields representing the model properties |
| 2016 | * @returns {object} An object containing one property for each field of the model |
| 2017 | **/ |
| 2018 | |
| 2019 | this.parseModelField = function (fields) { |
| 2020 | return _.reduce(fields, function (form, f) { |
| 2021 | form[f] = {}; |
| 2022 | return form; |
| 2023 | }, {}); |
| 2024 | }; |
| 2025 | }]); |
| 2026 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2027 | //# sourceMappingURL=../../../maps/services/helpers/ui/form.helpers.js.map |
| 2028 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2029 | 'use strict'; |
| 2030 | |
| 2031 | (function () { |
| 2032 | 'use strict'; |
| 2033 | |
| 2034 | /** |
| 2035 | * @ngdoc service |
| 2036 | * @name xos.uiComponents.Comparator |
| 2037 | * @description |
| 2038 | * This factory define a function that replace the native angular.filter comparator. |
| 2039 | * |
| 2040 | * It is done to allow the comparation between (0|1) values with booleans. |
| 2041 | * >Note that this factory return a single function, not an object. |
| 2042 | * |
| 2043 | * The tipical usage of this factory is inside an `ng-repeat` |
| 2044 | * @example |
| 2045 | * <example module="comparator"> |
| 2046 | * <file name="index.html"> |
| 2047 | * <div ng-controller="sample as vm"> |
| 2048 | * <div class="row"> |
| 2049 | * <div class="col-xs-6"> |
| 2050 | * <label>Filter by name:</label> |
| 2051 | * <input class="form-control" type="text" ng-model="vm.query.name"/> |
| 2052 | * </div> |
| 2053 | * <div class="col-xs-6"> |
| 2054 | * <label>Filter by status:</label> |
| 2055 | * <select |
| 2056 | * ng-model="vm.query.status" |
| 2057 | * ng-options="i for i in [true, false]"> |
| 2058 | * </select> |
| 2059 | * </div> |
| 2060 | * </div> |
| 2061 | * <div ng-repeat="item in vm.data | filter:vm.query:vm.comparator"> |
| 2062 | * <div class="row"> |
| 2063 | * <div class="col-xs-6">{{item.name}}</div> |
| 2064 | * <div class="col-xs-6">{{item.status}}</div> |
| 2065 | * </div> |
| 2066 | * </div> |
| 2067 | * </div> |
| 2068 | * </file> |
| 2069 | * <file name="script.js"> |
| 2070 | * angular.module('comparator', ['xos.uiComponents']) |
| 2071 | * .controller('sample', function(Comparator){ |
| 2072 | * this.comparator = Comparator; |
| 2073 | * this.data = [ |
| 2074 | * {name: 'Jhon', status: 1}, |
| 2075 | * {name: 'Jack', status: 0}, |
| 2076 | * {name: 'Mike', status: 1}, |
| 2077 | * {name: 'Scott', status: 0} |
| 2078 | * ]; |
| 2079 | * }); |
| 2080 | * </file> |
| 2081 | * </example> |
| 2082 | **/ |
| 2083 | |
| 2084 | comparator.$inject = ["_"]; |
| 2085 | angular.module('xos.uiComponents').factory('Comparator', comparator); |
| 2086 | |
| 2087 | function comparator(_) { |
| 2088 | |
| 2089 | return function (actual, expected) { |
| 2090 | |
| 2091 | if (angular.isUndefined(actual)) { |
| 2092 | // No substring matching against `undefined` |
| 2093 | return false; |
| 2094 | } |
| 2095 | if (actual === null || expected === null) { |
| 2096 | // No substring matching against `null`; only match against `null` |
| 2097 | return actual === expected; |
| 2098 | } |
| 2099 | if (angular.isObject(expected) || angular.isObject(actual)) { |
| 2100 | return angular.equals(expected, actual); |
| 2101 | } |
| 2102 | |
| 2103 | if (_.isBoolean(actual) || _.isBoolean(expected)) { |
| 2104 | if (actual === 0 || actual === 1) { |
| 2105 | actual = !!actual; |
| 2106 | } |
| 2107 | return angular.equals(expected, actual); |
| 2108 | } |
| 2109 | |
| 2110 | if (!angular.isString(actual) || !angular.isString(expected)) { |
| 2111 | if (angular.isDefined(actual.toString) && angular.isDefined(expected.toString)) { |
| 2112 | actual = actual.toString(); |
| 2113 | expected = expected.toString(); |
| 2114 | } else { |
| 2115 | return actual === expected; |
| 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | actual = actual.toLowerCase() + ''; |
| 2120 | expected = expected.toLowerCase() + ''; |
| 2121 | return actual.indexOf(expected) !== -1; |
| 2122 | }; |
| 2123 | } |
| 2124 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2125 | //# sourceMappingURL=../../../maps/services/helpers/ui/comparator.service.js.map |
| 2126 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2127 | 'use strict'; |
| 2128 | |
| 2129 | (function () { |
| 2130 | 'use strict'; |
| 2131 | |
| 2132 | /** |
| 2133 | * @ngdoc overview |
| 2134 | * @name xos.helpers |
| 2135 | * @description |
| 2136 | * # xos.Helpers |
| 2137 | * A collection of helpers to work with XOS <br/> |
| 2138 | * Currently available components are: |
| 2139 | * - [NoHyperlinks](/#/module/xos.helpers.NoHyperlinks) |
| 2140 | * - [SetCSRFToken](/#/module/xos.helpers.SetCSRFToken) |
| 2141 | * - [xosNotification](/#/module/xos.helpers.xosNotification) |
| 2142 | * - [XosUserPrefs](/#/module/xos.helpers.XosUserPrefs) |
| 2143 | * <br/><br/> |
| 2144 | * A set of angular [$resource](https://docs.angularjs.org/api/ngResource/service/$resource) is provided to work with the API.<br> |
| 2145 | * You can find the documentation [here](#/rest-api) |
| 2146 | **/ |
| 2147 | |
| 2148 | config.$inject = ["$httpProvider", "$interpolateProvider", "$resourceProvider"]; |
| 2149 | angular.module('xos.helpers', ['ngCookies', 'ngResource', 'ngAnimate', 'xos.uiComponents']).config(config) |
| 2150 | |
| 2151 | /** |
| 2152 | * @ngdoc service |
| 2153 | * @name xos.helpers._ |
| 2154 | * @description Wrap [lodash](https://lodash.com/docs) in an Angular Service |
| 2155 | **/ |
| 2156 | |
| 2157 | .factory('_', ["$window", function ($window) { |
| 2158 | return $window._; |
| 2159 | }]); |
| 2160 | |
| 2161 | function config($httpProvider, $interpolateProvider, $resourceProvider) { |
| 2162 | $httpProvider.interceptors.push('SetCSRFToken'); |
| 2163 | |
| 2164 | // NOTE http://www.masnun.com/2013/09/18/django-rest-framework-angularjs-resource-trailing-slash-problem.html |
| 2165 | $resourceProvider.defaults.stripTrailingSlashes = false; |
| 2166 | } |
| 2167 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2168 | //# sourceMappingURL=maps/xosHelpers.module.js.map |
| 2169 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2170 | 'use strict'; |
| 2171 | |
| 2172 | (function () { |
| 2173 | 'use strict'; |
| 2174 | |
| 2175 | angular.module('xos.helpers') |
| 2176 | /** |
| 2177 | * @ngdoc service |
| 2178 | * @name xos.helpers.vSG-Collection |
| 2179 | * @description Angular resource to fetch /api/service/vsg/ |
| 2180 | **/ |
| 2181 | .service('vSG-Collection', ["$resource", function ($resource) { |
| 2182 | return $resource('/api/service/vsg/'); |
| 2183 | }]); |
| 2184 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2185 | //# sourceMappingURL=../../maps/services/rest/vSG.js.map |
| 2186 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2187 | 'use strict'; |
| 2188 | |
| 2189 | (function () { |
| 2190 | 'use strict'; |
| 2191 | |
| 2192 | angular.module('xos.helpers') |
| 2193 | /** |
| 2194 | * @ngdoc service |
| 2195 | * @name xos.helpers.vOLT-Collection |
| 2196 | * @description Angular resource to fetch /api/tenant/cord/volt/:volt_id/ |
| 2197 | **/ |
| 2198 | .service('vOLT-Collection', ["$resource", function ($resource) { |
| 2199 | return $resource('/api/tenant/cord/volt/:volt_id/', { volt_id: '@id' }, { |
| 2200 | update: { method: 'PUT' } |
| 2201 | }); |
| 2202 | }]); |
| 2203 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2204 | //# sourceMappingURL=../../maps/services/rest/vOLT.js.map |
| 2205 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2206 | 'use strict'; |
| 2207 | |
| 2208 | (function () { |
| 2209 | 'use strict'; |
| 2210 | |
| 2211 | angular.module('xos.helpers') |
| 2212 | /** |
| 2213 | * @ngdoc service |
| 2214 | * @name xos.helpers.Login |
| 2215 | * @description Angular resource to fetch /api/utility/login/ |
| 2216 | **/ |
| 2217 | .service('Login', ["$resource", function ($resource) { |
| 2218 | return $resource('/api/utility/login/'); |
| 2219 | }]) |
| 2220 | /** |
| 2221 | * @ngdoc service |
| 2222 | * @name xos.helpers.Logout |
| 2223 | * @description Angular resource to fetch /api/utility/logout/ |
| 2224 | **/ |
| 2225 | .service('Logout', ["$resource", function ($resource) { |
| 2226 | return $resource('/api/utility/logout/'); |
| 2227 | }]); |
| 2228 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2229 | //# sourceMappingURL=../../maps/services/rest/Utility.js.map |
| 2230 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2231 | 'use strict'; |
| 2232 | |
| 2233 | (function () { |
| 2234 | 'use strict'; |
| 2235 | |
| 2236 | angular.module('xos.helpers') |
| 2237 | /** |
| 2238 | * @ngdoc service |
| 2239 | * @name xos.helpers.Users |
| 2240 | * @description Angular resource to fetch /api/core/users/:id/ |
| 2241 | **/ |
| 2242 | .service('Users', ["$resource", function ($resource) { |
| 2243 | return $resource('/api/core/users/:id/', { id: '@id' }, { |
| 2244 | update: { method: 'PUT' } |
| 2245 | }); |
| 2246 | }]); |
| 2247 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2248 | //# sourceMappingURL=../../maps/services/rest/Users.js.map |
| 2249 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2250 | 'use strict'; |
| 2251 | |
| 2252 | (function () { |
| 2253 | 'use strict'; |
| 2254 | |
| 2255 | angular.module('xos.helpers') |
| 2256 | /** |
| 2257 | * @ngdoc service |
| 2258 | * @name xos.helpers.Truckroll |
| 2259 | * @description Angular resource to fetch /api/tenant/truckroll/:id/ |
| 2260 | **/ |
| 2261 | .service('Truckroll', ["$resource", function ($resource) { |
| 2262 | return $resource('/api/tenant/truckroll/:id/', { id: '@id' }, { |
| 2263 | update: { method: 'PUT' } |
| 2264 | }); |
| 2265 | }]); |
| 2266 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2267 | //# sourceMappingURL=../../maps/services/rest/Truckroll.js.map |
| 2268 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2269 | 'use strict'; |
| 2270 | |
| 2271 | (function () { |
| 2272 | 'use strict'; |
| 2273 | |
| 2274 | angular.module('xos.helpers') |
| 2275 | /** |
| 2276 | * @ngdoc service |
| 2277 | * @name xos.helpers.Tenant |
| 2278 | * @description Angular resource to fetch /api/core/tenant/:id/ |
| 2279 | **/ |
| 2280 | .service('Tenants', ["$resource", function ($resource) { |
| 2281 | return $resource('/api/core/tenants/:id/', { id: '@id' }, { |
| 2282 | update: { method: 'PUT' } |
| 2283 | }); |
| 2284 | }]); |
| 2285 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2286 | //# sourceMappingURL=../../maps/services/rest/Tenant.js.map |
| 2287 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2288 | 'use strict'; |
| 2289 | |
| 2290 | (function () { |
| 2291 | 'use strict'; |
| 2292 | |
| 2293 | angular.module('xos.helpers') |
| 2294 | /** |
| 2295 | * @ngdoc service |
| 2296 | * @name xos.helpers.Subscribers |
| 2297 | * @description Angular resource to fetch Subscribers |
| 2298 | **/ |
| 2299 | .service('Subscribers', ["$resource", function ($resource) { |
| 2300 | return $resource('/api/tenant/cord/subscriber/:id/', { id: '@id' }, { |
| 2301 | update: { method: 'PUT' }, |
| 2302 | /** |
| 2303 | * @ngdoc method |
| 2304 | * @name xos.helpers.Subscribers#View-a-Subscriber-Features-Detail |
| 2305 | * @methodOf xos.helpers.Subscribers |
| 2306 | * @description |
| 2307 | * View-a-Subscriber-Features-Detail |
| 2308 | **/ |
| 2309 | 'View-a-Subscriber-Features-Detail': { |
| 2310 | method: 'GET', |
| 2311 | isArray: false, |
| 2312 | url: '/api/tenant/cord/subscriber/:id/features/' |
| 2313 | }, |
| 2314 | /** |
| 2315 | * @ngdoc method |
| 2316 | * @name xos.helpers.Subscribers#Read-Subscriber-uplink_speed |
| 2317 | * @methodOf xos.helpers.Subscribers |
| 2318 | * @description |
| 2319 | * Read-Subscriber-uplink_speed |
| 2320 | **/ |
| 2321 | 'Read-Subscriber-uplink_speed': { |
| 2322 | method: 'GET', |
| 2323 | isArray: false, |
| 2324 | url: '/api/tenant/cord/subscriber/:id/features/uplink_speed/' |
| 2325 | }, |
| 2326 | /** |
| 2327 | * @ngdoc method |
| 2328 | * @name xos.helpers.Subscribers#Update-Subscriber-uplink_speed |
| 2329 | * @methodOf xos.helpers.Subscribers |
| 2330 | * @description |
| 2331 | * Update-Subscriber-uplink_speed |
| 2332 | **/ |
| 2333 | 'Update-Subscriber-uplink_speed': { |
| 2334 | method: 'PUT', |
| 2335 | isArray: false, |
| 2336 | url: '/api/tenant/cord/subscriber/:id/features/uplink_speed/' |
| 2337 | }, |
| 2338 | /** |
| 2339 | * @ngdoc method |
| 2340 | * @name xos.helpers.Subscribers#Read-Subscriber-downlink_speed |
| 2341 | * @methodOf xos.helpers.Subscribers |
| 2342 | * @description |
| 2343 | * Read-Subscriber-downlink_speed |
| 2344 | **/ |
| 2345 | 'Read-Subscriber-downlink_speed': { |
| 2346 | method: 'GET', |
| 2347 | isArray: false, |
| 2348 | url: '/api/tenant/cord/subscriber/:id/features/downlink_speed/' |
| 2349 | }, |
| 2350 | /** |
| 2351 | * @ngdoc method |
| 2352 | * @name xos.helpers.Subscribers#Update-Subscriber-downlink_speed |
| 2353 | * @methodOf xos.helpers.Subscribers |
| 2354 | * @description |
| 2355 | * Update-Subscriber-downlink_speed |
| 2356 | **/ |
| 2357 | 'Update-Subscriber-downlink_speed': { |
| 2358 | method: 'PUT', |
| 2359 | isArray: false, |
| 2360 | url: '/api/tenant/cord/subscriber/:id/features/downlink_speed/' |
| 2361 | }, |
| 2362 | /** |
| 2363 | * @ngdoc method |
| 2364 | * @name xos.helpers.Subscribers#Read-Subscriber-cdn |
| 2365 | * @methodOf xos.helpers.Subscribers |
| 2366 | * @description |
| 2367 | * Read-Subscriber-cdn |
| 2368 | **/ |
| 2369 | 'Read-Subscriber-cdn': { |
| 2370 | method: 'GET', |
| 2371 | isArray: false, |
| 2372 | url: '/api/tenant/cord/subscriber/:id/features/cdn/' |
| 2373 | }, |
| 2374 | /** |
| 2375 | * @ngdoc method |
| 2376 | * @name xos.helpers.Subscribers#Update-Subscriber-cdn |
| 2377 | * @methodOf xos.helpers.Subscribers |
| 2378 | * @description |
| 2379 | * Update-Subscriber-cdn |
| 2380 | **/ |
| 2381 | 'Update-Subscriber-cdn': { |
| 2382 | method: 'PUT', |
| 2383 | isArray: false, |
| 2384 | url: '/api/tenant/cord/subscriber/:id/features/cdn/' |
| 2385 | }, |
| 2386 | /** |
| 2387 | * @ngdoc method |
| 2388 | * @name xos.helpers.Subscribers#Read-Subscriber-uverse |
| 2389 | * @methodOf xos.helpers.Subscribers |
| 2390 | * @description |
| 2391 | * Read-Subscriber-uverse |
| 2392 | **/ |
| 2393 | 'Read-Subscriber-uverse': { |
| 2394 | method: 'GET', |
| 2395 | isArray: false, |
| 2396 | url: '/api/tenant/cord/subscriber/:id/features/uverse/' |
| 2397 | }, |
| 2398 | /** |
| 2399 | * @ngdoc method |
| 2400 | * @name xos.helpers.Subscribers#Update-Subscriber-uverse |
| 2401 | * @methodOf xos.helpers.Subscribers |
| 2402 | * @description |
| 2403 | * Update-Subscriber-uverse |
| 2404 | **/ |
| 2405 | 'Update-Subscriber-uverse': { |
| 2406 | method: 'PUT', |
| 2407 | isArray: false, |
| 2408 | url: '/api/tenant/cord/subscriber/:id/features/uverse/' |
| 2409 | }, |
| 2410 | /** |
| 2411 | * @ngdoc method |
| 2412 | * @name xos.helpers.Subscribers#Read-Subscriber-status |
| 2413 | * @methodOf xos.helpers.Subscribers |
| 2414 | * @description |
| 2415 | * Read-Subscriber-status |
| 2416 | **/ |
| 2417 | 'Read-Subscriber-status': { |
| 2418 | method: 'GET', |
| 2419 | isArray: false, |
| 2420 | url: '/api/tenant/cord/subscriber/:id/features/status/' |
| 2421 | }, |
| 2422 | /** |
| 2423 | * @ngdoc method |
| 2424 | * @name xos.helpers.Subscribers#Update-Subscriber-status |
| 2425 | * @methodOf xos.helpers.Subscribers |
| 2426 | * @description |
| 2427 | * Update-Subscriber-status |
| 2428 | **/ |
| 2429 | 'Update-Subscriber-status': { |
| 2430 | method: 'PUT', |
| 2431 | isArray: false, |
| 2432 | url: '/api/tenant/cord/subscriber/:id/features/status/' |
| 2433 | } |
| 2434 | }); |
| 2435 | }]); |
| 2436 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2437 | //# sourceMappingURL=../../maps/services/rest/Subscribers.js.map |
| 2438 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2439 | 'use strict'; |
| 2440 | |
| 2441 | (function () { |
| 2442 | 'use strict'; |
| 2443 | |
| 2444 | angular.module('xos.helpers') |
| 2445 | /** |
| 2446 | * @ngdoc service |
| 2447 | * @name xos.helpers.SlicesPlus |
| 2448 | * @description Angular resource to fetch /api/utility/slicesplus/ |
| 2449 | * This is a read-only API and only the `query` method is currently supported. |
| 2450 | **/ |
| 2451 | .service('SlicesPlus', ["$http", "$q", function ($http, $q) { |
| 2452 | this.query = function (params) { |
| 2453 | var deferred = $q.defer(); |
| 2454 | |
| 2455 | $http.get('/api/utility/slicesplus/', { params: params }).then(function (res) { |
| 2456 | deferred.resolve(res.data); |
| 2457 | }).catch(function (res) { |
| 2458 | deferred.reject(res.data); |
| 2459 | }); |
| 2460 | |
| 2461 | return { $promise: deferred.promise }; |
| 2462 | }; |
| 2463 | |
| 2464 | this.get = function (id, params) { |
| 2465 | var deferred = $q.defer(); |
| 2466 | |
| 2467 | $http.get('/api/utility/slicesplus/' + id, { params: params }).then(function (res) { |
| 2468 | deferred.resolve(res.data); |
| 2469 | }).catch(function (res) { |
| 2470 | deferred.reject(res.data); |
| 2471 | }); |
| 2472 | return { $promise: deferred.promise }; |
| 2473 | }; |
| 2474 | }]); |
| 2475 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2476 | //# sourceMappingURL=../../maps/services/rest/Slices_plus.js.map |
| 2477 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2478 | 'use strict'; |
| 2479 | |
| 2480 | (function () { |
| 2481 | 'use strict'; |
| 2482 | |
| 2483 | angular.module('xos.helpers') |
| 2484 | /** |
| 2485 | * @ngdoc service |
| 2486 | * @name xos.helpers.Slices |
| 2487 | * @description Angular resource to fetch /api/core/slices/:id/ |
| 2488 | **/ |
| 2489 | .service('Slices', ["$resource", function ($resource) { |
| 2490 | return $resource('/api/core/slices/:id/', { id: '@id' }, { |
| 2491 | update: { method: 'PUT' } |
| 2492 | }); |
| 2493 | }]); |
| 2494 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2495 | //# sourceMappingURL=../../maps/services/rest/Slices.js.map |
| 2496 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2497 | 'use strict'; |
| 2498 | |
| 2499 | (function () { |
| 2500 | 'use strict'; |
| 2501 | |
| 2502 | angular.module('xos.helpers') |
| 2503 | /** |
| 2504 | * @ngdoc service |
| 2505 | * @name xos.helpers.Sites |
| 2506 | * @description Angular resource to fetch /api/core/sites/:id/ |
| 2507 | **/ |
| 2508 | .service('Sites', ["$resource", function ($resource) { |
| 2509 | return $resource('/api/core/sites/:id/', { id: '@id' }, { |
| 2510 | update: { method: 'PUT' } |
| 2511 | }); |
| 2512 | }]); |
| 2513 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2514 | //# sourceMappingURL=../../maps/services/rest/Sites.js.map |
| 2515 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2516 | 'use strict'; |
| 2517 | |
| 2518 | (function () { |
| 2519 | 'use strict'; |
| 2520 | |
| 2521 | angular.module('xos.helpers') |
| 2522 | /** |
| 2523 | * @ngdoc service |
| 2524 | * @name xos.helpers.Services |
| 2525 | * @description Angular resource to fetch /api/core/services/:id/ |
| 2526 | **/ |
| 2527 | .service('Services', ["$resource", function ($resource) { |
| 2528 | return $resource('/api/core/services/:id/', { id: '@id' }, { |
| 2529 | update: { method: 'PUT' } |
| 2530 | }); |
| 2531 | }]); |
| 2532 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2533 | //# sourceMappingURL=../../maps/services/rest/Services.js.map |
| 2534 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2535 | 'use strict'; |
| 2536 | |
| 2537 | (function () { |
| 2538 | 'use strict'; |
| 2539 | |
| 2540 | angular.module('xos.helpers') |
| 2541 | /** |
| 2542 | * @ngdoc service |
| 2543 | * @name xos.helpers.ONOS-Services-Collection |
| 2544 | * @description Angular resource to fetch /api/service/onos/ |
| 2545 | **/ |
| 2546 | .service('ONOS-Services-Collection', ["$resource", function ($resource) { |
| 2547 | return $resource('/api/service/onos/'); |
| 2548 | }]); |
| 2549 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2550 | //# sourceMappingURL=../../maps/services/rest/ONOS-Services.js.map |
| 2551 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2552 | 'use strict'; |
| 2553 | |
| 2554 | (function () { |
| 2555 | 'use strict'; |
| 2556 | |
| 2557 | angular.module('xos.helpers') |
| 2558 | /** |
| 2559 | * @ngdoc service |
| 2560 | * @name xos.helpers.ONOS-App-Collection |
| 2561 | * @description Angular resource to fetch /api/tenant/onos/app/ |
| 2562 | **/ |
| 2563 | .service('ONOS-App-Collection', ["$resource", function ($resource) { |
| 2564 | return $resource('/api/tenant/onos/app/'); |
| 2565 | }]); |
| 2566 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2567 | //# sourceMappingURL=../../maps/services/rest/ONOS-Apps.js.map |
| 2568 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2569 | 'use strict'; |
| 2570 | |
| 2571 | (function () { |
| 2572 | 'use strict'; |
| 2573 | |
| 2574 | angular.module('xos.helpers') |
| 2575 | /** |
| 2576 | * @ngdoc service |
| 2577 | * @name xos.helpers.Nodes |
| 2578 | * @description Angular resource to fetch /api/core/nodes/:id/ |
| 2579 | **/ |
| 2580 | .service('Nodes', ["$resource", function ($resource) { |
| 2581 | return $resource('/api/core/nodes/:id/', { id: '@id' }, { |
| 2582 | update: { method: 'PUT' } |
| 2583 | }); |
| 2584 | }]); |
| 2585 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2586 | //# sourceMappingURL=../../maps/services/rest/Nodes.js.map |
| 2587 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2588 | 'use strict'; |
| 2589 | |
| 2590 | (function () { |
| 2591 | 'use strict'; |
| 2592 | |
| 2593 | angular.module('xos.helpers') |
| 2594 | /** |
| 2595 | * @ngdoc service |
| 2596 | * @name xos.helpers.Networkstemplates |
| 2597 | * @description Angular resource to fetch /api/core/networktemplates/:id/ |
| 2598 | **/ |
| 2599 | .service('Networkstemplates', ["$resource", function ($resource) { |
| 2600 | return $resource('/api/core/networktemplates/:id/', { id: '@id' }, { |
| 2601 | update: { method: 'PUT' } |
| 2602 | }); |
| 2603 | }]); |
| 2604 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2605 | //# sourceMappingURL=../../maps/services/rest/Networkstemplates.js.map |
| 2606 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2607 | 'use strict'; |
| 2608 | |
| 2609 | (function () { |
| 2610 | 'use strict'; |
| 2611 | |
| 2612 | angular.module('xos.helpers') |
| 2613 | /** |
| 2614 | * @ngdoc service |
| 2615 | * @name xos.helpers.Networks |
| 2616 | * @description Angular resource to fetch /api/core/networks/:id/ |
| 2617 | **/ |
| 2618 | .service('Networks', ["$resource", function ($resource) { |
| 2619 | return $resource('/api/core/networks/:id/', { id: '@id' }, { |
| 2620 | update: { method: 'PUT' } |
| 2621 | }); |
| 2622 | }]); |
| 2623 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2624 | //# sourceMappingURL=../../maps/services/rest/Networks.js.map |
| 2625 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2626 | 'use strict'; |
| 2627 | |
| 2628 | (function () { |
| 2629 | 'use strict'; |
| 2630 | |
| 2631 | angular.module('xos.helpers') |
| 2632 | /**
|
| 2633 | * @ngdoc service
|
| 2634 | * @name xos.helpers.Me
|
| 2635 | * @description Http read-only api to fetch /api/utility/me/
|
| 2636 | **/ |
| 2637 | .service('Me', ["$q", "$http", function ($q, $http) { |
| 2638 | |
| 2639 | this.get = function () { |
| 2640 | var deferred = $q.defer(); |
| 2641 | |
| 2642 | $http.get('/api/utility/me/').then(function (res) { |
| 2643 | deferred.resolve(res.data); |
| 2644 | }).catch(function (e) { |
| 2645 | deferred.reject(e); |
| 2646 | }); |
| 2647 | return deferred.promise; |
| 2648 | }; |
| 2649 | }]); |
| 2650 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2651 | //# sourceMappingURL=../../maps/services/rest/Me.js.map |
| 2652 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2653 | 'use strict'; |
| 2654 | |
| 2655 | (function () { |
| 2656 | 'use strict'; |
| 2657 | |
| 2658 | angular.module('xos.helpers') |
| 2659 | /** |
| 2660 | * @ngdoc service |
| 2661 | * @name xos.helpers.Instances |
| 2662 | * @description Angular resource to fetch /api/core/instances/:id/ |
| 2663 | **/ |
| 2664 | .service('Instances', ["$resource", function ($resource) { |
| 2665 | return $resource('/api/core/instances/:id/', { id: '@id' }, { |
| 2666 | update: { method: 'PUT' } |
| 2667 | }); |
| 2668 | }]); |
| 2669 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2670 | //# sourceMappingURL=../../maps/services/rest/Instances.js.map |
| 2671 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2672 | 'use strict'; |
| 2673 | |
| 2674 | (function () { |
| 2675 | 'use strict'; |
| 2676 | |
| 2677 | angular.module('xos.helpers') |
| 2678 | /** |
| 2679 | * @ngdoc service |
| 2680 | * @name xos.helpers.Images |
| 2681 | * @description Angular resource to fetch /api/core/images/ |
| 2682 | **/ |
| 2683 | .service('Images', ["$resource", function ($resource) { |
| 2684 | return $resource('/api/core/images/:id/', { id: '@id' }, { |
| 2685 | update: { method: 'PUT' } |
| 2686 | }); |
| 2687 | }]); |
| 2688 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2689 | //# sourceMappingURL=../../maps/services/rest/Images.js.map |
| 2690 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2691 | 'use strict'; |
| 2692 | |
| 2693 | (function () { |
| 2694 | 'use strict'; |
| 2695 | |
| 2696 | angular.module('xos.helpers') |
| 2697 | /** |
| 2698 | * @ngdoc service |
| 2699 | * @name xos.helpers.Flavors |
| 2700 | * @description Angular resource to fetch /api/core/flavors/:id/ |
| 2701 | **/ |
| 2702 | .service('Flavors', ["$resource", function ($resource) { |
| 2703 | return $resource('/api/core/flavors/:id/', { id: '@id' }, { |
| 2704 | update: { method: 'PUT' } |
| 2705 | }); |
| 2706 | }]); |
| 2707 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2708 | //# sourceMappingURL=../../maps/services/rest/Flavors.js.map |
| 2709 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2710 | 'use strict'; |
| 2711 | |
| 2712 | (function () { |
| 2713 | 'use strict'; |
| 2714 | |
| 2715 | angular.module('xos.helpers') |
| 2716 | /** |
| 2717 | * @ngdoc service |
| 2718 | * @name xos.helpers.Example-Services-Collection |
| 2719 | * @description Angular resource to fetch /api/service/exampleservice/ |
| 2720 | **/ |
| 2721 | .service('Example-Services-Collection', ["$resource", function ($resource) { |
| 2722 | return $resource('/api/service/exampleservice/'); |
| 2723 | }]); |
| 2724 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2725 | //# sourceMappingURL=../../maps/services/rest/Example.js.map |
| 2726 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2727 | 'use strict'; |
| 2728 | |
| 2729 | (function () { |
| 2730 | 'use strict'; |
| 2731 | |
| 2732 | angular.module('xos.helpers') |
| 2733 | /** |
| 2734 | * @ngdoc service |
| 2735 | * @name xos.helpers.Deployments |
| 2736 | * @description Angular resource to fetch /api/core/deployments/:id/ |
| 2737 | **/ |
| 2738 | .service('Deployments', ["$resource", function ($resource) { |
| 2739 | return $resource('/api/core/deployments/:id/', { id: '@id' }, { |
| 2740 | update: { method: 'PUT' } |
| 2741 | }); |
| 2742 | }]); |
| 2743 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2744 | //# sourceMappingURL=../../maps/services/rest/Deployments.js.map |
| 2745 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2746 | 'use strict'; |
| 2747 | |
| 2748 | (function () { |
| 2749 | 'use strict'; |
| 2750 | |
| 2751 | angular.module('xos.helpers') |
| 2752 | /** |
| 2753 | * @ngdoc service |
| 2754 | * @name xos.helpers.Dashboards |
| 2755 | * @description Angular resource to fetch /api/core/dashboardviews/:id/ |
| 2756 | **/ |
| 2757 | .service('Dashboards', ["$resource", "$q", "$http", function ($resource, $q, $http) { |
| 2758 | var r = $resource('/api/core/dashboardviews/:id/', { id: '@id' }, { |
| 2759 | update: { method: 'PUT' } |
| 2760 | }); |
| 2761 | |
| 2762 | r.prototype.$save = function () { |
| 2763 | var d = $q.defer(); |
| 2764 | |
| 2765 | $http.put('/api/core/dashboardviews/' + this.id + '/', this).then(function (res) { |
| 2766 | d.resolve(res.data); |
| 2767 | }).catch(function (e) { |
| 2768 | d.reject(e.data); |
| 2769 | }); |
| 2770 | |
| 2771 | return d.promise; |
| 2772 | }; |
| 2773 | |
| 2774 | return r; |
| 2775 | }]); |
| 2776 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2777 | //# sourceMappingURL=../../maps/services/rest/Dashboards.js.map |
| 2778 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2779 | 'use strict'; |
| 2780 | |
| 2781 | (function () { |
| 2782 | |
| 2783 | angular.module('xos.helpers') |
| 2784 | |
| 2785 | /**
|
| 2786 | * @ngdoc service
|
| 2787 | * @name xos.helpers.XosUserPrefs
|
| 2788 | * @description
|
| 2789 | * This service is used to store the user preferences in cookies, so that they survive to page changes.
|
| 2790 | * The structure of the user preference is:
|
| 2791 | * ```
|
| 2792 | * {
|
| 2793 | * synchronizers: {
|
| 2794 | * notification: {
|
| 2795 | * 'volt': boolean,
|
| 2796 | * 'openstack': boolean,
|
| 2797 | * ...
|
| 2798 | * }
|
| 2799 | * }
|
| 2800 | * userData: {
|
| 2801 | * current_user_site_id: Number,
|
| 2802 | * current_user_site_user_names: Array[1],
|
| 2803 | * ...
|
| 2804 | * }
|
| 2805 | * }
|
| 2806 | * ```
|
| 2807 | **/ |
| 2808 | |
| 2809 | .service('XosUserPrefs', ["$cookies", "Me", "$q", function ($cookies, Me, $q) { |
| 2810 | var _this = this; |
| 2811 | |
| 2812 | var userPrefs = $cookies.get('xosUserPrefs') ? angular.fromJson($cookies.get('xosUserPrefs')) : {}; |
| 2813 | |
| 2814 | /**
|
| 2815 | * @ngdoc method
|
| 2816 | * @name xos.helpers.XosUserPrefs#getAll
|
| 2817 | * @methodOf xos.helpers.XosUserPrefs
|
| 2818 | * @description
|
| 2819 | * Return all the user preferences stored in cookies
|
| 2820 | * @returns {object} The user preferences
|
| 2821 | **/ |
| 2822 | this.getAll = function () { |
| 2823 | userPrefs = $cookies.get('xosUserPrefs') ? angular.fromJson($cookies.get('xosUserPrefs')) : {}; |
| 2824 | return userPrefs; |
| 2825 | }; |
| 2826 | |
| 2827 | /**
|
| 2828 | * @ngdoc method
|
| 2829 | * @name xos.helpers.XosUserPrefs#setAll
|
| 2830 | * @methodOf xos.helpers.XosUserPrefs
|
| 2831 | * @description
|
| 2832 | * Override all user preferences
|
| 2833 | * @param {object} prefs The user preferences
|
| 2834 | **/ |
| 2835 | this.setAll = function (prefs) { |
| 2836 | $cookies.put('xosUserPrefs', angular.toJson(prefs)); |
| 2837 | }; |
| 2838 | |
| 2839 | /**
|
| 2840 | * @ngdoc method
|
| 2841 | * @name xos.helpers.XosUserPrefs#getSynchronizerNotificationStatus
|
| 2842 | * @methodOf xos.helpers.XosUserPrefs
|
| 2843 | * @description
|
| 2844 | * Return the synchronizer notification status, if name is not provided return the status for all synchronizers
|
| 2845 | * @param {string=} prefs The synchronizer name
|
| 2846 | * @returns {object | string} The synchronizer status
|
| 2847 | **/ |
| 2848 | this.getSynchronizerNotificationStatus = function () { |
| 2849 | var name = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; |
| 2850 | |
| 2851 | if (name) { |
| 2852 | return _this.getAll().synchronizers.notification[name]; |
| 2853 | } |
| 2854 | return _this.getAll().synchronizers.notification; |
| 2855 | }; |
| 2856 | |
| 2857 | /**
|
| 2858 | * @ngdoc method
|
| 2859 | * @name xos.helpers.XosUserPrefs#getUserDetailsCookie
|
| 2860 | * @methodOf xos.helpers.XosUserPrefs
|
| 2861 | * @description
|
| 2862 | * Return all the user details stored in cookies or call the service
|
| 2863 | * @returns {object} The user details
|
| 2864 | **/ |
| 2865 | this.getUserDetailsCookie = function () { |
| 2866 | var defer = $q.defer(); |
| 2867 | var localPref = _this.getAll(); |
| 2868 | if (!localPref.userData) { |
| 2869 | _this.setUserDetailsCookie().$promise.then(function (data) { |
| 2870 | defer.resolve(data); |
| 2871 | }); |
| 2872 | } else { |
| 2873 | defer.resolve(localPref.userData); |
| 2874 | } |
| 2875 | return { $promise: defer.promise }; |
| 2876 | }; |
| 2877 | |
| 2878 | /**
|
| 2879 | * @ngdoc method
|
| 2880 | * @name xos.helpers.XosUserPrefs#setUserDetailsCookie
|
| 2881 | * @methodOf xos.helpers.XosUserPrefs
|
| 2882 | * @description
|
| 2883 | * Save the user details in the cookie
|
| 2884 | * @param {object} details stored in cookie
|
| 2885 | * @param {objects} returns the user details as a promise
|
| 2886 | **/ |
| 2887 | this.setUserDetailsCookie = function () { |
| 2888 | var userData = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; |
| 2889 | |
| 2890 | |
| 2891 | var defer = $q.defer(); |
| 2892 | var cookies = _this.getAll(); |
| 2893 | if (!userData) { |
| 2894 | Me.get().then(function (user) { |
| 2895 | cookies.userData = user; |
| 2896 | _this.setAll(cookies); |
| 2897 | defer.resolve(user); |
| 2898 | }).catch(function (e) { |
| 2899 | defer.reject(e); |
| 2900 | }); |
| 2901 | } else { |
| 2902 | cookies.userData = userData; |
| 2903 | _this.setAll(cookies); |
| 2904 | defer.resolve(userData); |
| 2905 | } |
| 2906 | return { $promise: defer.promise }; |
| 2907 | }; |
| 2908 | |
| 2909 | /**
|
| 2910 | * @ngdoc method
|
| 2911 | * @name xos.helpers.XosUserPrefs#setSynchronizerNotificationStatus
|
| 2912 | * @methodOf xos.helpers.XosUserPrefs
|
| 2913 | * @description
|
| 2914 | * Update the notification status for a single synchronizer
|
| 2915 | * @param {string} name The synchronizer name
|
| 2916 | * @param {boolean} value The notification status (true means that it has been sent)
|
| 2917 | **/ |
| 2918 | |
| 2919 | this.setSynchronizerNotificationStatus = function () { |
| 2920 | var name = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; |
| 2921 | var value = arguments[1]; |
| 2922 | |
| 2923 | if (!name) { |
| 2924 | throw new Error('[XosUserPrefs] When updating a synchronizer is mandatory to provide a name.'); |
| 2925 | } |
| 2926 | |
| 2927 | var cookies = _this.getAll(); |
| 2928 | |
| 2929 | if (!cookies.synchronizers) { |
| 2930 | cookies.synchronizers = { |
| 2931 | notification: {} |
| 2932 | }; |
| 2933 | } |
| 2934 | cookies.synchronizers.notification[name] = value; |
| 2935 | _this.setAll(cookies); |
| 2936 | }; |
| 2937 | }]); |
| 2938 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2939 | //# sourceMappingURL=../../maps/services/helpers/user-prefs.service.js.map |
| 2940 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2941 | 'use strict'; |
| 2942 | |
| 2943 | (function () { |
| 2944 | 'use strict'; |
| 2945 | |
| 2946 | /** |
| 2947 | * @ngdoc service |
| 2948 | * @name xos.helpers.ServiceGraph |
| 2949 | * @description This factory define a set of helper function to query the service tenancy graph |
| 2950 | **/ |
| 2951 | |
| 2952 | angular.module('xos.helpers').service('GraphService', ["$q", "Tenants", "Services", function ($q, Tenants, Services) { |
| 2953 | var _this = this; |
| 2954 | |
| 2955 | this.loadCoarseData = function () { |
| 2956 | |
| 2957 | var services = void 0; |
| 2958 | |
| 2959 | var deferred = $q.defer(); |
| 2960 | |
| 2961 | Services.query().$promise.then(function (res) { |
| 2962 | services = res; |
| 2963 | return Tenants.query({ kind: 'coarse' }).$promise; |
| 2964 | }).then(function (tenants) { |
| 2965 | deferred.resolve({ |
| 2966 | tenants: tenants, |
| 2967 | services: services |
| 2968 | }); |
| 2969 | }); |
| 2970 | |
| 2971 | return deferred.promise; |
| 2972 | }; |
| 2973 | |
| 2974 | this.getCoarseGraph = function () { |
| 2975 | _this.loadCoarseData().then(function (res) { |
| 2976 | console.log(res); |
| 2977 | }); |
| 2978 | return 'ciao'; |
| 2979 | }; |
| 2980 | }]); |
| 2981 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 2982 | //# sourceMappingURL=../maps/services/service_graph.service.js.map |
| 2983 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 2984 | 'use strict'; |
| 2985 | |
| 2986 | /* eslint-disable angular/ng_window_service*/ |
| 2987 | (function () { |
| 2988 | 'use strict'; |
| 2989 | |
| 2990 | angular.module('xos.helpers').factory('Notification', function () { |
| 2991 | return window.Notification; |
| 2992 | }) |
| 2993 | /** |
| 2994 | * @ngdoc service |
| 2995 | * @name xos.helpers.xosNotification |
| 2996 | * @description This factory define a set of helper function to trigger desktop notification |
| 2997 | **/ |
| 2998 | .service('xosNotification', ["$q", "$log", "Notification", function ($q, $log, Notification) { |
| 2999 | var _this = this; |
| 3000 | |
| 3001 | this.checkPermission = function () { |
| 3002 | var deferred = $q.defer(); |
| 3003 | Notification.requestPermission().then(function (permission) { |
| 3004 | if (permission === 'granted') { |
| 3005 | deferred.resolve(permission); |
| 3006 | } else { |
| 3007 | deferred.reject(permission); |
| 3008 | } |
| 3009 | }); |
| 3010 | return deferred.promise; |
| 3011 | }; |
| 3012 | |
| 3013 | this.sendNotification = function (title, options) { |
| 3014 | var notification = new Notification(title, options); |
| 3015 | notification.onerror = function (err) { |
| 3016 | $log.error(err); |
| 3017 | }; |
| 3018 | }; |
| 3019 | |
| 3020 | /** |
| 3021 | * @ngdoc method |
| 3022 | * @name xos.helpers.xosNotification#notify |
| 3023 | * @methodOf xos.helpers.xosNotification |
| 3024 | * @description |
| 3025 | * This method will check for user permission and if granted will send a browser notification. |
| 3026 | * @param {string} title The notification title |
| 3027 | * @param {object} options The notification options: `{icon: 'url', body: 'Notification body'}` |
| 3028 | **/ |
| 3029 | |
| 3030 | this.notify = function (title, options) { |
| 3031 | if (!('Notification' in window)) { |
| 3032 | $log.info('This browser does not support desktop notification'); |
| 3033 | } else if (Notification.permission !== 'granted') { |
| 3034 | _this.checkPermission().then(function () { |
| 3035 | return _this.sendNotification(title, options); |
| 3036 | }); |
| 3037 | } else if (Notification.permission === 'granted') { |
| 3038 | _this.sendNotification(title, options); |
| 3039 | } |
| 3040 | }; |
| 3041 | }]); |
| 3042 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 3043 | //# sourceMappingURL=../maps/services/notification.service.js.map |
| 3044 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 3045 | 'use strict'; |
| 3046 | |
| 3047 | (function () { |
| 3048 | 'use strict'; |
| 3049 | |
| 3050 | /** |
| 3051 | * @ngdoc service |
| 3052 | * @name xos.helpers.NoHyperlinks |
| 3053 | * @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 |
| 3054 | **/ |
| 3055 | |
| 3056 | angular.module('xos.helpers').factory('NoHyperlinks', noHyperlinks); |
| 3057 | |
| 3058 | function noHyperlinks() { |
| 3059 | return { |
| 3060 | request: function request(_request) { |
| 3061 | if (_request.url.indexOf('.html') === -1) { |
| 3062 | _request.url += '?no_hyperlinks=1'; |
| 3063 | } |
| 3064 | return _request; |
| 3065 | } |
| 3066 | }; |
| 3067 | } |
| 3068 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 3069 | //# sourceMappingURL=../maps/services/noHyperlinks.interceptor.js.map |
| 3070 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 3071 | 'use strict'; |
| 3072 | |
| 3073 | // TODO write tests for log |
| 3074 | |
| 3075 | /* eslint-disable angular/ng_window_service*/ |
| 3076 | |
| 3077 | angular.module('xos.helpers').config(['$provide', function ($provide) { |
| 3078 | // Use the `decorator` solution to substitute or attach behaviors to |
| 3079 | // original service instance; @see angular-mocks for more examples.... |
| 3080 | |
| 3081 | $provide.decorator('$log', ['$delegate', function ($delegate) { |
| 3082 | |
| 3083 | var isLogEnabled = function isLogEnabled() { |
| 3084 | return window.location.href.indexOf('debug=true') >= 0; |
| 3085 | }; |
| 3086 | // Save the original $log.debug() |
| 3087 | var logFn = $delegate.log; |
| 3088 | var infoFn = $delegate.info; |
| 3089 | var warnFn = $delegate.warn; |
| 3090 | //let errorFn = $delegate.error; |
| 3091 | var debugFn = $delegate.debug; |
| 3092 | |
| 3093 | // create the replacement function |
| 3094 | var replacement = function replacement(fn) { |
| 3095 | return function () { |
| 3096 | //console.log(`Is Log Enabled: ${isLogEnabled()}`) |
| 3097 | if (!isLogEnabled()) { |
| 3098 | // console.log('logging is disabled'); |
| 3099 | return; |
| 3100 | } |
| 3101 | |
| 3102 | var args = [].slice.call(arguments); |
| 3103 | var now = new Date(); |
| 3104 | |
| 3105 | // Prepend timestamp |
| 3106 | args[0] = '[' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds() + '] ' + args[0]; |
| 3107 | |
| 3108 | // HACK awfull fix for angular mock implementation whithin jasmine test failing issue |
| 3109 | if (angular.isFunction($delegate.reset) && !($delegate.debug.logs instanceof Array)) { |
| 3110 | // if we are within the mock and did not reset yet, we call it to avoid issue |
| 3111 | // console.log('mock log impl fix to avoid logs array not existing...'); |
| 3112 | $delegate.reset(); |
| 3113 | } |
| 3114 | |
| 3115 | // Call the original with the output prepended with formatted timestamp |
| 3116 | |
| 3117 | return fn.apply(null, args); |
| 3118 | }; |
| 3119 | }; |
| 3120 | |
| 3121 | $delegate.info = replacement(infoFn); |
| 3122 | $delegate.log = replacement(logFn); |
| 3123 | $delegate.warn = replacement(warnFn); |
| 3124 | //$delegate.error = replacement(errorFn); // note this will prevent errors to be printed |
| 3125 | $delegate.debug = replacement(debugFn); |
| 3126 | |
| 3127 | return $delegate; |
| 3128 | }]); |
| 3129 | }]); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 3130 | //# sourceMappingURL=../maps/services/log.decorator.js.map |
| 3131 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 3132 | 'use strict'; |
| 3133 | |
| 3134 | (function () { |
| 3135 | 'use strict'; |
| 3136 | |
| 3137 | /** |
| 3138 | * @ngdoc service |
| 3139 | * @name xos.helpers.SetCSRFToken |
| 3140 | * @description This factory is automatically loaded trough xos.helpers and will add an $http interceptor that will the CSRF-Token to your request headers |
| 3141 | **/ |
| 3142 | |
| 3143 | setCSRFToken.$inject = ["$cookies"]; |
| 3144 | angular.module('xos.helpers').factory('SetCSRFToken', setCSRFToken); |
| 3145 | |
| 3146 | function setCSRFToken($cookies) { |
| 3147 | return { |
| 3148 | request: function request(_request) { |
| 3149 | if (_request.method !== 'GET') { |
| 3150 | _request.headers['X-CSRFToken'] = $cookies.get('xoscsrftoken'); |
| 3151 | } |
| 3152 | return _request; |
| 3153 | } |
| 3154 | }; |
| 3155 | } |
| 3156 | })(); |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 3157 | //# sourceMappingURL=../maps/services/csrfToken.interceptor.js.map |
| 3158 | |
Matteo Scandolo | a71ccfd | 2016-07-22 10:19:15 -0700 | [diff] [blame] | 3159 | /** |
| 3160 | * @ngdoc overview |
| 3161 | * @name ngXosLib |
| 3162 | * @id index |
| 3163 | * @description |
| 3164 | * # Welcome to the ngXosLib documentation! <br/> |
| 3165 | * This is the module that group all the helpers service and UI components for XOS. |
| 3166 | * <br/><br/> |
| 3167 | * You can find all the documentation related to the UI Component Library here: <a href="#/module/xos.uiComponents"> xos.uiComponents</a> <br/> |
| 3168 | * and the documentation related to all the other helpers here: <a href="#/module/xos.helpers"> xos.helpers</a> <br/> |
| 3169 | * ## Issues |
| 3170 | * Please report issues at https://jira.opencord.org |
| 3171 | **/ |
Steven Burrows | 8481848 | 2016-09-29 15:33:46 -0700 | [diff] [blame] | 3172 | "use strict"; |
| 3173 | //# sourceMappingURL=maps/index.ngdoc.js.map |