@everymatrix/stage-mm-verification-report 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chunk-A3NTIEMP.js +1 -0
- package/chunk-CAY35YP7.js +7 -0
- package/chunk-H3QHLLCN.js +1 -0
- package/chunk-KE4BCZO4.js +851 -0
- package/chunk-OHPEWN32.js +1198 -0
- package/chunk-WSQOM5HU.js +1 -0
- package/component-lib.js +1 -0
- package/index.html +12 -0
- package/main.js +3264 -0
- package/modules/angular/LICENSE.md +21 -0
- package/modules/angular/README.md +67 -0
- package/modules/angular/angular-csp.css +25 -0
- package/modules/angular/angular.js +36600 -0
- package/modules/angular/angular.min.js +352 -0
- package/modules/angular/angular.min.js.gzip +0 -0
- package/modules/angular/angular.min.js.map +8 -0
- package/modules/angular/bower.json +9 -0
- package/modules/angular/index.js +2 -0
- package/modules/angular/package.json +25 -0
- package/modules/angular-ui-grid/CHANGELOG.md +1973 -0
- package/modules/angular-ui-grid/README.md +59 -0
- package/modules/angular-ui-grid/css/ui-grid.cellnav.css +25 -0
- package/modules/angular-ui-grid/css/ui-grid.cellnav.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.core.css +866 -0
- package/modules/angular-ui-grid/css/ui-grid.core.min.css +5 -0
- package/modules/angular-ui-grid/css/ui-grid.edit.css +23 -0
- package/modules/angular-ui-grid/css/ui-grid.edit.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.empty-base-layer.css +6 -0
- package/modules/angular-ui-grid/css/ui-grid.empty-base-layer.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.expandable.css +16 -0
- package/modules/angular-ui-grid/css/ui-grid.expandable.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.exporter.css +0 -0
- package/modules/angular-ui-grid/css/ui-grid.exporter.min.css +0 -0
- package/modules/angular-ui-grid/css/ui-grid.grouping.css +3 -0
- package/modules/angular-ui-grid/css/ui-grid.grouping.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.importer.css +0 -0
- package/modules/angular-ui-grid/css/ui-grid.importer.min.css +0 -0
- package/modules/angular-ui-grid/css/ui-grid.move-columns.css +9 -0
- package/modules/angular-ui-grid/css/ui-grid.move-columns.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.pagination.css +299 -0
- package/modules/angular-ui-grid/css/ui-grid.pagination.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.pinning.css +67 -0
- package/modules/angular-ui-grid/css/ui-grid.pinning.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.resize-columns.css +38 -0
- package/modules/angular-ui-grid/css/ui-grid.resize-columns.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.row-edit.css +9 -0
- package/modules/angular-ui-grid/css/ui-grid.row-edit.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.selection.css +25 -0
- package/modules/angular-ui-grid/css/ui-grid.selection.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.tree-base.css +4 -0
- package/modules/angular-ui-grid/css/ui-grid.tree-base.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.tree-view.css +6 -0
- package/modules/angular-ui-grid/css/ui-grid.tree-view.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.validate.css +3 -0
- package/modules/angular-ui-grid/css/ui-grid.validate.min.css +1 -0
- package/modules/angular-ui-grid/fonts/ui-grid.eot +0 -0
- package/modules/angular-ui-grid/fonts/ui-grid.svg +56 -0
- package/modules/angular-ui-grid/fonts/ui-grid.ttf +0 -0
- package/modules/angular-ui-grid/fonts/ui-grid.woff +0 -0
- package/modules/angular-ui-grid/less/animation.less +85 -0
- package/modules/angular-ui-grid/less/body.less +84 -0
- package/modules/angular-ui-grid/less/cell.less +46 -0
- package/modules/angular-ui-grid/less/cellnav.less +29 -0
- package/modules/angular-ui-grid/less/core.less +11 -0
- package/modules/angular-ui-grid/less/edit.less +27 -0
- package/modules/angular-ui-grid/less/elements.less +156 -0
- package/modules/angular-ui-grid/less/emptyBaseLayer.less +8 -0
- package/modules/angular-ui-grid/less/expandable.less +29 -0
- package/modules/angular-ui-grid/less/exporter.less +4 -0
- package/modules/angular-ui-grid/less/footer.less +76 -0
- package/modules/angular-ui-grid/less/grid.less +86 -0
- package/modules/angular-ui-grid/less/grouping.less +5 -0
- package/modules/angular-ui-grid/less/header.less +250 -0
- package/modules/angular-ui-grid/less/icons.less +151 -0
- package/modules/angular-ui-grid/less/importer.less +4 -0
- package/modules/angular-ui-grid/less/main.less +2 -0
- package/modules/angular-ui-grid/less/menu.less +91 -0
- package/modules/angular-ui-grid/less/moveColumns.less +12 -0
- package/modules/angular-ui-grid/less/pagination.less +297 -0
- package/modules/angular-ui-grid/less/pinning.less +86 -0
- package/modules/angular-ui-grid/less/resizeColumns.less +53 -0
- package/modules/angular-ui-grid/less/rowEdit.less +19 -0
- package/modules/angular-ui-grid/less/rtl.less +67 -0
- package/modules/angular-ui-grid/less/selection.less +29 -0
- package/modules/angular-ui-grid/less/sorting.less +16 -0
- package/modules/angular-ui-grid/less/treeBase.less +6 -0
- package/modules/angular-ui-grid/less/treeView.less +8 -0
- package/modules/angular-ui-grid/less/validate.less +5 -0
- package/modules/angular-ui-grid/less/variables.less +90 -0
- package/modules/angular-ui-grid/package.json +144 -0
- package/modules/angular-ui-grid/ui-grid.auto-resize.js +69 -0
- package/modules/angular-ui-grid/ui-grid.auto-resize.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.cellnav.js +1181 -0
- package/modules/angular-ui-grid/ui-grid.cellnav.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.core.js +12737 -0
- package/modules/angular-ui-grid/ui-grid.core.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.css +3208 -0
- package/modules/angular-ui-grid/ui-grid.edit.js +1325 -0
- package/modules/angular-ui-grid/ui-grid.edit.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.empty-base-layer.js +178 -0
- package/modules/angular-ui-grid/ui-grid.empty-base-layer.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.expandable.js +651 -0
- package/modules/angular-ui-grid/ui-grid.expandable.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.exporter.js +1777 -0
- package/modules/angular-ui-grid/ui-grid.exporter.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.grouping.js +1291 -0
- package/modules/angular-ui-grid/ui-grid.grouping.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.importer.js +791 -0
- package/modules/angular-ui-grid/ui-grid.importer.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.infinite-scroll.js +552 -0
- package/modules/angular-ui-grid/ui-grid.infinite-scroll.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.js +30867 -0
- package/modules/angular-ui-grid/ui-grid.language.all.js +3214 -0
- package/modules/angular-ui-grid/ui-grid.language.all.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ar.js +118 -0
- package/modules/angular-ui-grid/ui-grid.language.ar.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.bg.js +115 -0
- package/modules/angular-ui-grid/ui-grid.language.bg.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.cs.js +96 -0
- package/modules/angular-ui-grid/ui-grid.language.cs.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.da.js +90 -0
- package/modules/angular-ui-grid/ui-grid.language.da.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.de.js +133 -0
- package/modules/angular-ui-grid/ui-grid.language.de.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.es-ct.js +133 -0
- package/modules/angular-ui-grid/ui-grid.language.es-ct.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.es.js +106 -0
- package/modules/angular-ui-grid/ui-grid.language.es.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.fa.js +93 -0
- package/modules/angular-ui-grid/ui-grid.language.fa.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.fi.js +76 -0
- package/modules/angular-ui-grid/ui-grid.language.fi.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.fr.js +128 -0
- package/modules/angular-ui-grid/ui-grid.language.fr.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.he.js +71 -0
- package/modules/angular-ui-grid/ui-grid.language.he.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.hy.js +76 -0
- package/modules/angular-ui-grid/ui-grid.language.hy.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.is.js +118 -0
- package/modules/angular-ui-grid/ui-grid.language.is.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.it.js +112 -0
- package/modules/angular-ui-grid/ui-grid.language.it.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ja.js +118 -0
- package/modules/angular-ui-grid/ui-grid.language.ja.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ko.js +77 -0
- package/modules/angular-ui-grid/ui-grid.language.ko.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.nl.js +91 -0
- package/modules/angular-ui-grid/ui-grid.language.nl.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.no.js +115 -0
- package/modules/angular-ui-grid/ui-grid.language.no.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.pl.js +126 -0
- package/modules/angular-ui-grid/ui-grid.language.pl.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.pt-br.js +133 -0
- package/modules/angular-ui-grid/ui-grid.language.pt-br.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.pt.js +133 -0
- package/modules/angular-ui-grid/ui-grid.language.pt.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ro.js +112 -0
- package/modules/angular-ui-grid/ui-grid.language.ro.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.rs-lat.js +126 -0
- package/modules/angular-ui-grid/ui-grid.language.rs-lat.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ru.js +115 -0
- package/modules/angular-ui-grid/ui-grid.language.ru.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.sk.js +127 -0
- package/modules/angular-ui-grid/ui-grid.language.sk.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.sv.js +126 -0
- package/modules/angular-ui-grid/ui-grid.language.sv.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ta.js +87 -0
- package/modules/angular-ui-grid/ui-grid.language.ta.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.tr.js +112 -0
- package/modules/angular-ui-grid/ui-grid.language.tr.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ua.js +112 -0
- package/modules/angular-ui-grid/ui-grid.language.ua.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.zh-cn.js +112 -0
- package/modules/angular-ui-grid/ui-grid.language.zh-cn.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.zh-tw.js +77 -0
- package/modules/angular-ui-grid/ui-grid.language.zh-tw.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.min.css +5 -0
- package/modules/angular-ui-grid/ui-grid.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.move-columns.js +582 -0
- package/modules/angular-ui-grid/ui-grid.move-columns.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.pagination.js +510 -0
- package/modules/angular-ui-grid/ui-grid.pagination.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.pinning.js +281 -0
- package/modules/angular-ui-grid/ui-grid.pinning.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.resize-columns.js +574 -0
- package/modules/angular-ui-grid/ui-grid.resize-columns.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.row-edit.js +717 -0
- package/modules/angular-ui-grid/ui-grid.row-edit.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.saveState.js +831 -0
- package/modules/angular-ui-grid/ui-grid.saveState.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.selection.js +1196 -0
- package/modules/angular-ui-grid/ui-grid.selection.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.tree-base.js +1743 -0
- package/modules/angular-ui-grid/ui-grid.tree-base.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.tree-view.js +218 -0
- package/modules/angular-ui-grid/ui-grid.tree-view.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.validate.js +589 -0
- package/modules/angular-ui-grid/ui-grid.validate.min.js +6 -0
- package/package.json +8 -0
- package/polyfills.js +2 -0
- package/styles.css +1 -0
|
@@ -0,0 +1,791 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ui-grid - v4.12.7 - 2024-04-12
|
|
3
|
+
* http://ui-grid.info/
|
|
4
|
+
* Copyright (c) 2024 ; License: MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
(function () {
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @ngdoc overview
|
|
12
|
+
* @name ui.grid.importer
|
|
13
|
+
* @description
|
|
14
|
+
*
|
|
15
|
+
* # ui.grid.importer
|
|
16
|
+
*
|
|
17
|
+
* <div class="alert alert-success" role="alert"><strong>Stable</strong> This feature is stable. There should no longer be breaking api changes without a deprecation warning.</div>
|
|
18
|
+
*
|
|
19
|
+
* This module provides the ability to import data into the grid. It
|
|
20
|
+
* uses the column defs to work out which data belongs in which column,
|
|
21
|
+
* and creates entities from a configured class (typically a $resource).
|
|
22
|
+
*
|
|
23
|
+
* If the rowEdit feature is enabled, it also calls save on those newly
|
|
24
|
+
* created objects, and then displays any errors in the imported data.
|
|
25
|
+
*
|
|
26
|
+
* Currently the importer imports only CSV and json files, although provision has been
|
|
27
|
+
* made to process other file formats, and these can be added over time.
|
|
28
|
+
*
|
|
29
|
+
* For json files, the properties within each object in the json must match the column names
|
|
30
|
+
* (to put it another way, the importer doesn't process the json, it just copies the objects
|
|
31
|
+
* within the json into a new instance of the specified object type)
|
|
32
|
+
*
|
|
33
|
+
* For CSV import, the default column identification relies on each column in the
|
|
34
|
+
* header row matching a column.name or column.displayName. Optionally, a column identification
|
|
35
|
+
* callback can be used. This allows matching using other attributes, which is particularly
|
|
36
|
+
* useful if your application has internationalised column headings (i.e. the headings that
|
|
37
|
+
* the user sees don't match the column names).
|
|
38
|
+
*
|
|
39
|
+
* The importer makes use of the grid menu as the UI for requesting an
|
|
40
|
+
* import.
|
|
41
|
+
*
|
|
42
|
+
* <div ui-grid-importer></div>
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
var module = angular.module('ui.grid.importer', ['ui.grid']);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @ngdoc object
|
|
49
|
+
* @name ui.grid.importer.constant:uiGridImporterConstants
|
|
50
|
+
*
|
|
51
|
+
* @description constants available in importer module
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
module.constant('uiGridImporterConstants', {
|
|
55
|
+
featureName: 'importer'
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @ngdoc service
|
|
60
|
+
* @name ui.grid.importer.service:uiGridImporterService
|
|
61
|
+
*
|
|
62
|
+
* @description Services for importer feature
|
|
63
|
+
*/
|
|
64
|
+
module.service('uiGridImporterService', ['$q', 'uiGridConstants', 'uiGridImporterConstants', 'gridUtil', '$compile', '$interval', 'i18nService', '$window',
|
|
65
|
+
function ($q, uiGridConstants, uiGridImporterConstants, gridUtil, $compile, $interval, i18nService, $window) {
|
|
66
|
+
|
|
67
|
+
var service = {
|
|
68
|
+
|
|
69
|
+
initializeGrid: function ($scope, grid) {
|
|
70
|
+
|
|
71
|
+
// add feature namespace and any properties to grid for needed state
|
|
72
|
+
grid.importer = {
|
|
73
|
+
$scope: $scope
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
this.defaultGridOptions(grid.options);
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @ngdoc object
|
|
80
|
+
* @name ui.grid.importer.api:PublicApi
|
|
81
|
+
*
|
|
82
|
+
* @description Public Api for importer feature
|
|
83
|
+
*/
|
|
84
|
+
var publicApi = {
|
|
85
|
+
events: {
|
|
86
|
+
importer: {
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
methods: {
|
|
90
|
+
importer: {
|
|
91
|
+
/**
|
|
92
|
+
* @ngdoc function
|
|
93
|
+
* @name importFile
|
|
94
|
+
* @methodOf ui.grid.importer.api:PublicApi
|
|
95
|
+
* @description Imports a file into the grid using the file object
|
|
96
|
+
* provided. Bypasses the grid menu
|
|
97
|
+
* @param {File} fileObject the file we want to import, as a javascript
|
|
98
|
+
* File object
|
|
99
|
+
*/
|
|
100
|
+
importFile: function ( fileObject ) {
|
|
101
|
+
service.importThisFile( grid, fileObject );
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
grid.api.registerEventsFromObject(publicApi.events);
|
|
108
|
+
|
|
109
|
+
grid.api.registerMethodsFromObject(publicApi.methods);
|
|
110
|
+
|
|
111
|
+
if ( grid.options.enableImporter && grid.options.importerShowMenu ) {
|
|
112
|
+
if ( grid.api.core.addToGridMenu ) {
|
|
113
|
+
service.addToMenu( grid );
|
|
114
|
+
} else {
|
|
115
|
+
// order of registration is not guaranteed, register in a little while
|
|
116
|
+
$interval( function() {
|
|
117
|
+
if (grid.api.core.addToGridMenu) {
|
|
118
|
+
service.addToMenu( grid );
|
|
119
|
+
}
|
|
120
|
+
}, 100, 1);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
defaultGridOptions: function (gridOptions) {
|
|
127
|
+
// default option to true unless it was explicitly set to false
|
|
128
|
+
/**
|
|
129
|
+
* @ngdoc object
|
|
130
|
+
* @name ui.grid.importer.api:GridOptions
|
|
131
|
+
*
|
|
132
|
+
* @description GridOptions for importer feature, these are available to be
|
|
133
|
+
* set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @ngdoc property
|
|
138
|
+
* @propertyOf ui.grid.importer.api:GridOptions
|
|
139
|
+
* @name enableImporter
|
|
140
|
+
* @description Whether or not importer is enabled. Automatically set
|
|
141
|
+
* to false if the user's browser does not support the required fileApi.
|
|
142
|
+
* Otherwise defaults to true.
|
|
143
|
+
*
|
|
144
|
+
*/
|
|
145
|
+
if (gridOptions.enableImporter || gridOptions.enableImporter === undefined) {
|
|
146
|
+
if ( !($window.hasOwnProperty('File') && $window.hasOwnProperty('FileReader') && $window.hasOwnProperty('FileList') && $window.hasOwnProperty('Blob')) ) {
|
|
147
|
+
gridUtil.logError('The File APIs are not fully supported in this browser, grid importer cannot be used.');
|
|
148
|
+
gridOptions.enableImporter = false;
|
|
149
|
+
} else {
|
|
150
|
+
gridOptions.enableImporter = true;
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
gridOptions.enableImporter = false;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @ngdoc method
|
|
158
|
+
* @name importerProcessHeaders
|
|
159
|
+
* @methodOf ui.grid.importer.api:GridOptions
|
|
160
|
+
* @description A callback function that will process headers using custom
|
|
161
|
+
* logic. Set this callback function if the headers that your user will provide in their
|
|
162
|
+
* import file don't necessarily match the grid header or field names. This might commonly
|
|
163
|
+
* occur where your application is internationalised, and therefore the field names
|
|
164
|
+
* that the user recognises are in a different language than the field names that
|
|
165
|
+
* ui-grid knows about.
|
|
166
|
+
*
|
|
167
|
+
* Defaults to the internal `processHeaders` method, which seeks to match using both
|
|
168
|
+
* displayName and column.name. Any non-matching columns are discarded.
|
|
169
|
+
*
|
|
170
|
+
* Your callback routine should respond by processing the header array, and returning an array
|
|
171
|
+
* of matching column names. A null value in any given position means "don't import this column"
|
|
172
|
+
*
|
|
173
|
+
* <pre>
|
|
174
|
+
* gridOptions.importerProcessHeaders: function( grid, headerArray ) {
|
|
175
|
+
* var myHeaderColumns = [];
|
|
176
|
+
* var thisCol;
|
|
177
|
+
* headerArray.forEach( function( value, index ) {
|
|
178
|
+
* thisCol = mySpecialLookupFunction( value );
|
|
179
|
+
* myHeaderColumns.push( thisCol.name );
|
|
180
|
+
* });
|
|
181
|
+
*
|
|
182
|
+
* return myHeaderCols;
|
|
183
|
+
* })
|
|
184
|
+
* </pre>
|
|
185
|
+
* @param {Grid} grid the grid we're importing into
|
|
186
|
+
* @param {array} headerArray an array of the text from the first row of the csv file,
|
|
187
|
+
* which you need to match to column.names
|
|
188
|
+
* @returns {array} array of matching column names, in the same order as the headerArray
|
|
189
|
+
*
|
|
190
|
+
*/
|
|
191
|
+
gridOptions.importerProcessHeaders = gridOptions.importerProcessHeaders || service.processHeaders;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @ngdoc method
|
|
195
|
+
* @name importerHeaderFilter
|
|
196
|
+
* @methodOf ui.grid.importer.api:GridOptions
|
|
197
|
+
* @description A callback function that will filter (usually translate) a single
|
|
198
|
+
* header. Used when you want to match the passed in column names to the column
|
|
199
|
+
* displayName after the header filter.
|
|
200
|
+
*
|
|
201
|
+
* Your callback routine needs to return the filtered header value.
|
|
202
|
+
* <pre>
|
|
203
|
+
* gridOptions.importerHeaderFilter: function( displayName ) {
|
|
204
|
+
* return $translate.instant( displayName );
|
|
205
|
+
* })
|
|
206
|
+
* </pre>
|
|
207
|
+
*
|
|
208
|
+
* or:
|
|
209
|
+
* <pre>
|
|
210
|
+
* gridOptions.importerHeaderFilter: $translate.instant
|
|
211
|
+
* </pre>
|
|
212
|
+
* @param {string} displayName the displayName that we'd like to translate
|
|
213
|
+
* @returns {string} the translated name
|
|
214
|
+
*
|
|
215
|
+
*/
|
|
216
|
+
gridOptions.importerHeaderFilter = gridOptions.importerHeaderFilter || function( displayName ) { return displayName; };
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @ngdoc method
|
|
220
|
+
* @name importerErrorCallback
|
|
221
|
+
* @methodOf ui.grid.importer.api:GridOptions
|
|
222
|
+
* @description A callback function that provides custom error handling, rather
|
|
223
|
+
* than the standard grid behaviour of an alert box and a console message. You
|
|
224
|
+
* might use this to internationalise the console log messages, or to write to a
|
|
225
|
+
* custom logging routine that returned errors to the server.
|
|
226
|
+
*
|
|
227
|
+
* <pre>
|
|
228
|
+
* gridOptions.importerErrorCallback: function( grid, errorKey, consoleMessage, context ) {
|
|
229
|
+
* myUserDisplayRoutine( errorKey );
|
|
230
|
+
* myLoggingRoutine( consoleMessage, context );
|
|
231
|
+
* })
|
|
232
|
+
* </pre>
|
|
233
|
+
* @param {Grid} grid the grid we're importing into, may be useful if you're positioning messages
|
|
234
|
+
* in some way
|
|
235
|
+
* @param {string} errorKey one of the i18n keys the importer can return - importer.noHeaders,
|
|
236
|
+
* importer.noObjects, importer.invalidCsv, importer.invalidJson, importer.jsonNotArray
|
|
237
|
+
* @param {string} consoleMessage the English console message that importer would have written
|
|
238
|
+
* @param {object} context the context data that importer would have appended to that console message,
|
|
239
|
+
* often the file content itself or the element that is in error
|
|
240
|
+
*
|
|
241
|
+
*/
|
|
242
|
+
if ( !gridOptions.importerErrorCallback || typeof(gridOptions.importerErrorCallback) !== 'function' ) {
|
|
243
|
+
delete gridOptions.importerErrorCallback;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @ngdoc method
|
|
248
|
+
* @name importerDataAddCallback
|
|
249
|
+
* @methodOf ui.grid.importer.api:GridOptions
|
|
250
|
+
* @description A mandatory callback function that adds data to the source data array. The grid
|
|
251
|
+
* generally doesn't add rows to the source data array, it is tidier to handle this through a user
|
|
252
|
+
* callback.
|
|
253
|
+
*
|
|
254
|
+
* <pre>
|
|
255
|
+
* gridOptions.importerDataAddCallback: function( grid, newObjects ) {
|
|
256
|
+
* $scope.myData = $scope.myData.concat( newObjects );
|
|
257
|
+
* })
|
|
258
|
+
* </pre>
|
|
259
|
+
* @param {Grid} grid the grid we're importing into, may be useful in some way
|
|
260
|
+
* @param {array} newObjects an array of new objects that you should add to your data
|
|
261
|
+
*
|
|
262
|
+
*/
|
|
263
|
+
if ( gridOptions.enableImporter === true && !gridOptions.importerDataAddCallback ) {
|
|
264
|
+
gridUtil.logError("You have not set an importerDataAddCallback, importer is disabled");
|
|
265
|
+
gridOptions.enableImporter = false;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @ngdoc object
|
|
270
|
+
* @name importerNewObject
|
|
271
|
+
* @propertyOf ui.grid.importer.api:GridOptions
|
|
272
|
+
* @description An object on which we call `new` to create each new row before inserting it into
|
|
273
|
+
* the data array. Typically this would be a $resource entity, which means that if you're using
|
|
274
|
+
* the rowEdit feature, you can directly call save on this entity when the save event is triggered.
|
|
275
|
+
*
|
|
276
|
+
* Defaults to a vanilla javascript object
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* <pre>
|
|
280
|
+
* gridOptions.importerNewObject = MyRes;
|
|
281
|
+
* </pre>
|
|
282
|
+
*
|
|
283
|
+
*/
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* @ngdoc property
|
|
287
|
+
* @propertyOf ui.grid.importer.api:GridOptions
|
|
288
|
+
* @name importerShowMenu
|
|
289
|
+
* @description Whether or not to show an item in the grid menu. Defaults to true.
|
|
290
|
+
*
|
|
291
|
+
*/
|
|
292
|
+
gridOptions.importerShowMenu = gridOptions.importerShowMenu !== false;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* @ngdoc method
|
|
296
|
+
* @methodOf ui.grid.importer.api:GridOptions
|
|
297
|
+
* @name importerObjectCallback
|
|
298
|
+
* @description A callback that massages the data for each object. For example,
|
|
299
|
+
* you might have data stored as a code value, but display the decode. This callback
|
|
300
|
+
* can be used to change the decoded value back into a code. Defaults to doing nothing.
|
|
301
|
+
* @param {Grid} grid in case you need it
|
|
302
|
+
* @param {object} newObject the new object as importer has created it, modify it
|
|
303
|
+
* then return the modified version
|
|
304
|
+
* @returns {object} the modified object
|
|
305
|
+
* @example
|
|
306
|
+
* <pre>
|
|
307
|
+
* gridOptions.importerObjectCallback = function ( grid, newObject ) {
|
|
308
|
+
* switch newObject.status {
|
|
309
|
+
* case 'Active':
|
|
310
|
+
* newObject.status = 1;
|
|
311
|
+
* break;
|
|
312
|
+
* case 'Inactive':
|
|
313
|
+
* newObject.status = 2;
|
|
314
|
+
* break;
|
|
315
|
+
* }
|
|
316
|
+
* return newObject;
|
|
317
|
+
* };
|
|
318
|
+
* </pre>
|
|
319
|
+
*/
|
|
320
|
+
gridOptions.importerObjectCallback = gridOptions.importerObjectCallback || function( grid, newObject ) { return newObject; };
|
|
321
|
+
},
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* @ngdoc function
|
|
326
|
+
* @name addToMenu
|
|
327
|
+
* @methodOf ui.grid.importer.service:uiGridImporterService
|
|
328
|
+
* @description Adds import menu item to the grid menu,
|
|
329
|
+
* allowing the user to request import of a file
|
|
330
|
+
* @param {Grid} grid the grid into which data should be imported
|
|
331
|
+
*/
|
|
332
|
+
addToMenu: function ( grid ) {
|
|
333
|
+
grid.api.core.addToGridMenu( grid, [
|
|
334
|
+
{
|
|
335
|
+
title: i18nService.getSafeText('gridMenu.importerTitle'),
|
|
336
|
+
order: 150
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
templateUrl: 'ui-grid/importerMenuItemContainer',
|
|
340
|
+
action: function () {
|
|
341
|
+
this.grid.api.importer.importAFile( grid );
|
|
342
|
+
},
|
|
343
|
+
order: 151
|
|
344
|
+
}
|
|
345
|
+
]);
|
|
346
|
+
},
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* @ngdoc function
|
|
351
|
+
* @name importThisFile
|
|
352
|
+
* @methodOf ui.grid.importer.service:uiGridImporterService
|
|
353
|
+
* @description Imports the provided file into the grid using the file object
|
|
354
|
+
* provided. Bypasses the grid menu
|
|
355
|
+
* @param {Grid} grid the grid we're importing into
|
|
356
|
+
* @param {File} fileObject the file we want to import, as returned from the File
|
|
357
|
+
* javascript object
|
|
358
|
+
*/
|
|
359
|
+
importThisFile: function ( grid, fileObject ) {
|
|
360
|
+
if (!fileObject) {
|
|
361
|
+
gridUtil.logError( 'No file object provided to importThisFile, should be impossible, aborting');
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
var reader = new FileReader();
|
|
366
|
+
|
|
367
|
+
switch ( fileObject.type ) {
|
|
368
|
+
case 'application/json':
|
|
369
|
+
reader.onload = service.importJsonClosure( grid );
|
|
370
|
+
break;
|
|
371
|
+
default:
|
|
372
|
+
reader.onload = service.importCsvClosure( grid );
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
reader.readAsText( fileObject );
|
|
377
|
+
},
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* @ngdoc function
|
|
382
|
+
* @name importJson
|
|
383
|
+
* @methodOf ui.grid.importer.service:uiGridImporterService
|
|
384
|
+
* @description Creates a function that imports a json file into the grid.
|
|
385
|
+
* The json data is imported into new objects of type `gridOptions.importerNewObject`,
|
|
386
|
+
* and if the rowEdit feature is enabled the rows are marked as dirty
|
|
387
|
+
* @param {Grid} grid the grid we want to import into
|
|
388
|
+
* @return {function} Function that receives the file that we want to import, as
|
|
389
|
+
* a FileObject as an argument
|
|
390
|
+
*/
|
|
391
|
+
importJsonClosure: function( grid ) {
|
|
392
|
+
return function( importFile ) {
|
|
393
|
+
var newObjects = [],
|
|
394
|
+
newObject,
|
|
395
|
+
importArray = service.parseJson( grid, importFile );
|
|
396
|
+
|
|
397
|
+
if (importArray === null) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
importArray.forEach( function( value ) {
|
|
401
|
+
newObject = service.newObject( grid );
|
|
402
|
+
angular.extend( newObject, value );
|
|
403
|
+
newObject = grid.options.importerObjectCallback( grid, newObject );
|
|
404
|
+
newObjects.push( newObject );
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
service.addObjects( grid, newObjects );
|
|
408
|
+
};
|
|
409
|
+
},
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* @ngdoc function
|
|
414
|
+
* @name parseJson
|
|
415
|
+
* @methodOf ui.grid.importer.service:uiGridImporterService
|
|
416
|
+
* @description Parses a json file, returns the parsed data.
|
|
417
|
+
* Displays an error if file doesn't parse
|
|
418
|
+
* @param {Grid} grid the grid that we want to import into
|
|
419
|
+
* @param {FileObject} importFile the file that we want to import, as
|
|
420
|
+
* a FileObject
|
|
421
|
+
* @returns {array} array of objects from the imported json
|
|
422
|
+
*/
|
|
423
|
+
parseJson: function( grid, importFile ) {
|
|
424
|
+
var loadedObjects;
|
|
425
|
+
|
|
426
|
+
try {
|
|
427
|
+
loadedObjects = JSON.parse( importFile.target.result );
|
|
428
|
+
} catch (e) {
|
|
429
|
+
service.alertError( grid, 'importer.invalidJson', 'File could not be processed, is it valid json? Content was: ', importFile.target.result );
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if ( !Array.isArray( loadedObjects ) ) {
|
|
434
|
+
service.alertError( grid, 'importer.jsonNotarray', 'Import failed, file is not an array, file was: ', importFile.target.result );
|
|
435
|
+
return [];
|
|
436
|
+
} else {
|
|
437
|
+
return loadedObjects;
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* @ngdoc function
|
|
445
|
+
* @name importCsvClosure
|
|
446
|
+
* @methodOf ui.grid.importer.service:uiGridImporterService
|
|
447
|
+
* @description Creates a function that imports a csv file into the grid
|
|
448
|
+
* (allowing it to be used in the reader.onload event)
|
|
449
|
+
* @param {Grid} grid the grid that we want to import into
|
|
450
|
+
* @return {function} Function that receives the file that we want to import, as
|
|
451
|
+
* a file object
|
|
452
|
+
*/
|
|
453
|
+
importCsvClosure: function( grid ) {
|
|
454
|
+
return function( importFile ) {
|
|
455
|
+
var importArray = service.parseCsv( importFile );
|
|
456
|
+
|
|
457
|
+
if ( !importArray || importArray.length < 1 ) {
|
|
458
|
+
service.alertError( grid, 'importer.invalidCsv', 'File could not be processed, is it valid csv? Content was: ', importFile.target.result );
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
var newObjects = service.createCsvObjects( grid, importArray );
|
|
463
|
+
|
|
464
|
+
if ( !newObjects || newObjects.length === 0 ) {
|
|
465
|
+
service.alertError( grid, 'importer.noObjects', 'Objects were not able to be derived, content was: ', importFile.target.result );
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
service.addObjects( grid, newObjects );
|
|
470
|
+
};
|
|
471
|
+
},
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* @ngdoc function
|
|
476
|
+
* @name parseCsv
|
|
477
|
+
* @methodOf ui.grid.importer.service:uiGridImporterService
|
|
478
|
+
* @description Parses a csv file into an array of arrays, with the first
|
|
479
|
+
* array being the headers, and the remaining arrays being the data.
|
|
480
|
+
* The logic for this comes from https://github.com/thetalecrafter/excel.js/blob/master/src/csv.js,
|
|
481
|
+
* which is noted as being under the MIT license. The code is modified to pass the jscs yoda condition
|
|
482
|
+
* checker
|
|
483
|
+
* @param {FileObject} importFile the file that we want to import, as a
|
|
484
|
+
* file object
|
|
485
|
+
*/
|
|
486
|
+
parseCsv: function( importFile ) {
|
|
487
|
+
var csv = importFile.target.result;
|
|
488
|
+
|
|
489
|
+
// use the CSV-JS library to parse
|
|
490
|
+
return CSV.parse(csv);
|
|
491
|
+
},
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* @ngdoc function
|
|
496
|
+
* @name createCsvObjects
|
|
497
|
+
* @methodOf ui.grid.importer.service:uiGridImporterService
|
|
498
|
+
* @description Converts an array of arrays (representing the csv file)
|
|
499
|
+
* into a set of objects. Uses the provided `gridOptions.importerNewObject`
|
|
500
|
+
* to create the objects, and maps the header row into the individual columns
|
|
501
|
+
* using either `gridOptions.importerProcessHeaders`, or by using a native method
|
|
502
|
+
* of matching to either the displayName, column name or column field of
|
|
503
|
+
* the columns in the column defs. The resulting objects will have attributes
|
|
504
|
+
* that are named based on the column.field or column.name, in that order.
|
|
505
|
+
* @param {Grid} grid the grid that we want to import into
|
|
506
|
+
* @param {Array} importArray the data that we want to import, as an array
|
|
507
|
+
*/
|
|
508
|
+
createCsvObjects: function( grid, importArray ) {
|
|
509
|
+
// pull off header row and turn into headers
|
|
510
|
+
var headerMapping = grid.options.importerProcessHeaders( grid, importArray.shift() );
|
|
511
|
+
|
|
512
|
+
if ( !headerMapping || headerMapping.length === 0 ) {
|
|
513
|
+
service.alertError( grid, 'importer.noHeaders', 'Column names could not be derived, content was: ', importArray );
|
|
514
|
+
return [];
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
var newObjects = [],
|
|
518
|
+
newObject;
|
|
519
|
+
|
|
520
|
+
importArray.forEach( function( row ) {
|
|
521
|
+
newObject = service.newObject( grid );
|
|
522
|
+
if ( row !== null ) {
|
|
523
|
+
row.forEach( function( field, index ) {
|
|
524
|
+
if ( headerMapping[index] !== null ) {
|
|
525
|
+
newObject[ headerMapping[index] ] = field;
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
newObject = grid.options.importerObjectCallback( grid, newObject );
|
|
530
|
+
newObjects.push( newObject );
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
return newObjects;
|
|
534
|
+
},
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* @ngdoc function
|
|
539
|
+
* @name processHeaders
|
|
540
|
+
* @methodOf ui.grid.importer.service:uiGridImporterService
|
|
541
|
+
* @description Determines the columns that the header row from
|
|
542
|
+
* a csv (or other) file represents.
|
|
543
|
+
* @param {Grid} grid the grid we're importing into
|
|
544
|
+
* @param {array} headerRow the header row that we wish to match against
|
|
545
|
+
* the column definitions
|
|
546
|
+
* @returns {array} an array of the attribute names that should be used
|
|
547
|
+
* for that column, based on matching the headers or creating the headers
|
|
548
|
+
*
|
|
549
|
+
*/
|
|
550
|
+
processHeaders: function( grid, headerRow ) {
|
|
551
|
+
var headers = [];
|
|
552
|
+
|
|
553
|
+
if ( !grid.options.columnDefs || grid.options.columnDefs.length === 0 ) {
|
|
554
|
+
// we are going to create new columnDefs for all these columns, so just remove
|
|
555
|
+
// spaces from the names to create fields
|
|
556
|
+
headerRow.forEach( function( value ) {
|
|
557
|
+
headers.push( value.replace( /[^0-9a-zA-Z\-_]/g, '_' ) );
|
|
558
|
+
});
|
|
559
|
+
return headers;
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
var lookupHash = service.flattenColumnDefs( grid, grid.options.columnDefs );
|
|
563
|
+
headerRow.forEach( function( value ) {
|
|
564
|
+
if ( lookupHash[value] ) {
|
|
565
|
+
headers.push( lookupHash[value] );
|
|
566
|
+
}
|
|
567
|
+
else if ( lookupHash[ value.toLowerCase() ] ) {
|
|
568
|
+
headers.push( lookupHash[ value.toLowerCase() ] );
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
headers.push( null );
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
return headers;
|
|
575
|
+
}
|
|
576
|
+
},
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* @name flattenColumnDefs
|
|
581
|
+
* @methodOf ui.grid.importer.service:uiGridImporterService
|
|
582
|
+
* @description Runs through the column defs and creates a hash of
|
|
583
|
+
* the displayName, name and field, and of each of those values forced to lower case,
|
|
584
|
+
* with each pointing to the field or name
|
|
585
|
+
* (whichever is present). Used to lookup column headers and decide what
|
|
586
|
+
* attribute name to give to the resulting field.
|
|
587
|
+
* @param {Grid} grid the grid we're importing into
|
|
588
|
+
* @param {array} columnDefs the columnDefs that we should flatten
|
|
589
|
+
* @returns {hash} the flattened version of the column def information, allowing
|
|
590
|
+
* us to look up a value by `flattenedHash[ headerValue ]`
|
|
591
|
+
*/
|
|
592
|
+
flattenColumnDefs: function( grid, columnDefs ) {
|
|
593
|
+
var flattenedHash = {};
|
|
594
|
+
|
|
595
|
+
columnDefs.forEach( function( columnDef) {
|
|
596
|
+
if ( columnDef.name ) {
|
|
597
|
+
flattenedHash[ columnDef.name ] = columnDef.field || columnDef.name;
|
|
598
|
+
flattenedHash[ columnDef.name.toLowerCase() ] = columnDef.field || columnDef.name;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
if ( columnDef.field ) {
|
|
602
|
+
flattenedHash[ columnDef.field ] = columnDef.field || columnDef.name;
|
|
603
|
+
flattenedHash[ columnDef.field.toLowerCase() ] = columnDef.field || columnDef.name;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
if ( columnDef.displayName ) {
|
|
607
|
+
flattenedHash[ columnDef.displayName ] = columnDef.field || columnDef.name;
|
|
608
|
+
flattenedHash[ columnDef.displayName.toLowerCase() ] = columnDef.field || columnDef.name;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
if ( columnDef.displayName && grid.options.importerHeaderFilter ) {
|
|
612
|
+
flattenedHash[ grid.options.importerHeaderFilter(columnDef.displayName) ] = columnDef.field || columnDef.name;
|
|
613
|
+
flattenedHash[ grid.options.importerHeaderFilter(columnDef.displayName).toLowerCase() ] = columnDef.field || columnDef.name;
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
return flattenedHash;
|
|
618
|
+
},
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* @ngdoc function
|
|
623
|
+
* @name addObjects
|
|
624
|
+
* @methodOf ui.grid.importer.service:uiGridImporterService
|
|
625
|
+
* @description Inserts our new objects into the grid data, and
|
|
626
|
+
* sets the rows to dirty if the rowEdit feature is being used
|
|
627
|
+
*
|
|
628
|
+
* Does this by registering a watch on dataChanges, which essentially
|
|
629
|
+
* is waiting on the result of the grid data watch, and downstream processing.
|
|
630
|
+
*
|
|
631
|
+
* When the callback is called, it deregisters itself - we don't want to run
|
|
632
|
+
* again next time data is added.
|
|
633
|
+
*
|
|
634
|
+
* If we never get called, we deregister on destroy.
|
|
635
|
+
*
|
|
636
|
+
* @param {Grid} grid the grid we're importing into
|
|
637
|
+
* @param {array} newObjects the objects we want to insert into the grid data
|
|
638
|
+
* @returns {object} the new object
|
|
639
|
+
*/
|
|
640
|
+
addObjects: function( grid, newObjects ) {
|
|
641
|
+
if ( grid.api.rowEdit ) {
|
|
642
|
+
var dataChangeDereg = grid.registerDataChangeCallback( function() {
|
|
643
|
+
grid.api.rowEdit.setRowsDirty( newObjects );
|
|
644
|
+
dataChangeDereg();
|
|
645
|
+
}, [uiGridConstants.dataChange.ROW] );
|
|
646
|
+
|
|
647
|
+
grid.importer.$scope.$on( '$destroy', dataChangeDereg );
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
grid.importer.$scope.$apply( grid.options.importerDataAddCallback( grid, newObjects ) );
|
|
651
|
+
|
|
652
|
+
},
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* @ngdoc function
|
|
657
|
+
* @name newObject
|
|
658
|
+
* @methodOf ui.grid.importer.service:uiGridImporterService
|
|
659
|
+
* @description Makes a new object based on `gridOptions.importerNewObject`,
|
|
660
|
+
* or based on an empty object if not present
|
|
661
|
+
* @param {Grid} grid the grid we're importing into
|
|
662
|
+
* @returns {object} the new object
|
|
663
|
+
*/
|
|
664
|
+
newObject: function( grid ) {
|
|
665
|
+
if ( typeof(grid.options) !== "undefined" && typeof(grid.options.importerNewObject) !== "undefined" ) {
|
|
666
|
+
return new grid.options.importerNewObject();
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
return {};
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* @ngdoc function
|
|
676
|
+
* @name alertError
|
|
677
|
+
* @methodOf ui.grid.importer.service:uiGridImporterService
|
|
678
|
+
* @description Provides an internationalised user alert for the failure,
|
|
679
|
+
* and logs a console message including diagnostic content.
|
|
680
|
+
* Optionally, if the the `gridOptions.importerErrorCallback` routine
|
|
681
|
+
* is defined, then calls that instead, allowing user specified error routines
|
|
682
|
+
* @param {Grid} grid the grid we're importing into
|
|
683
|
+
* @param {array} headerRow the header row that we wish to match against
|
|
684
|
+
* the column definitions
|
|
685
|
+
*/
|
|
686
|
+
alertError: function( grid, alertI18nToken, consoleMessage, context ) {
|
|
687
|
+
if ( grid.options.importerErrorCallback ) {
|
|
688
|
+
grid.options.importerErrorCallback( grid, alertI18nToken, consoleMessage, context );
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
$window.alert(i18nService.getSafeText( alertI18nToken ));
|
|
692
|
+
gridUtil.logError(consoleMessage + context );
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
return service;
|
|
698
|
+
|
|
699
|
+
}
|
|
700
|
+
]);
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* @ngdoc directive
|
|
704
|
+
* @name ui.grid.importer.directive:uiGridImporter
|
|
705
|
+
* @element div
|
|
706
|
+
* @restrict A
|
|
707
|
+
*
|
|
708
|
+
* @description Adds importer features to grid
|
|
709
|
+
*
|
|
710
|
+
*/
|
|
711
|
+
module.directive('uiGridImporter', ['uiGridImporterConstants', 'uiGridImporterService', 'gridUtil', '$compile',
|
|
712
|
+
function (uiGridImporterConstants, uiGridImporterService, gridUtil, $compile) {
|
|
713
|
+
return {
|
|
714
|
+
replace: true,
|
|
715
|
+
priority: 0,
|
|
716
|
+
require: '^uiGrid',
|
|
717
|
+
scope: false,
|
|
718
|
+
link: function ($scope, $elm, $attrs, uiGridCtrl) {
|
|
719
|
+
uiGridImporterService.initializeGrid($scope, uiGridCtrl.grid);
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
]);
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* @ngdoc directive
|
|
727
|
+
* @name ui.grid.importer.directive:uiGridImporterMenuItem
|
|
728
|
+
* @element div
|
|
729
|
+
* @restrict A
|
|
730
|
+
*
|
|
731
|
+
* @description Handles the processing from the importer menu item - once a file is
|
|
732
|
+
* selected
|
|
733
|
+
*
|
|
734
|
+
*/
|
|
735
|
+
module.directive('uiGridImporterMenuItem', ['uiGridImporterConstants', 'uiGridImporterService', 'gridUtil', '$compile',
|
|
736
|
+
function (uiGridImporterConstants, uiGridImporterService, gridUtil, $compile) {
|
|
737
|
+
return {
|
|
738
|
+
replace: true,
|
|
739
|
+
priority: 0,
|
|
740
|
+
require: '?^uiGrid',
|
|
741
|
+
scope: false,
|
|
742
|
+
templateUrl: 'ui-grid/importerMenuItem',
|
|
743
|
+
link: function ($scope, $elm, $attrs, uiGridCtrl) {
|
|
744
|
+
var grid;
|
|
745
|
+
|
|
746
|
+
function handleFileSelect(event) {
|
|
747
|
+
var target = event.srcElement || event.target;
|
|
748
|
+
|
|
749
|
+
if (target && target.files && target.files.length === 1) {
|
|
750
|
+
var fileObject = target.files[0];
|
|
751
|
+
|
|
752
|
+
// Define grid if the uiGrid controller is present
|
|
753
|
+
if (typeof(uiGridCtrl) !== 'undefined' && uiGridCtrl) {
|
|
754
|
+
grid = uiGridCtrl.grid;
|
|
755
|
+
|
|
756
|
+
uiGridImporterService.importThisFile( grid, fileObject );
|
|
757
|
+
target.form.reset();
|
|
758
|
+
}
|
|
759
|
+
else {
|
|
760
|
+
gridUtil.logError('Could not import file because UI Grid was not found.');
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
var fileChooser = $elm[0].querySelectorAll('.ui-grid-importer-file-chooser');
|
|
766
|
+
|
|
767
|
+
if ( fileChooser.length !== 1 ) {
|
|
768
|
+
gridUtil.logError('Found > 1 or < 1 file choosers within the menu item, error, cannot continue');
|
|
769
|
+
}
|
|
770
|
+
else {
|
|
771
|
+
fileChooser[0].addEventListener('change', handleFileSelect, false);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
]);
|
|
777
|
+
})();
|
|
778
|
+
|
|
779
|
+
angular.module('ui.grid.importer').run(['$templateCache', function($templateCache) {
|
|
780
|
+
'use strict';
|
|
781
|
+
|
|
782
|
+
$templateCache.put('ui-grid/importerMenuItem',
|
|
783
|
+
"<li class=\"ui-grid-menu-item\"><form><input class=\"ui-grid-importer-file-chooser\" type=\"file\" id=\"files\" name=\"files[]\"></form></li>"
|
|
784
|
+
);
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
$templateCache.put('ui-grid/importerMenuItemContainer',
|
|
788
|
+
"<div ui-grid-importer-menu-item></div>"
|
|
789
|
+
);
|
|
790
|
+
|
|
791
|
+
}]);
|