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