1 define([], function (){
5 * Base history request object
7 * @param PathUtilsService
8 * @param YangUtilsService
9 * @param ParsingJsonService
11 function HistoryRequestModel(PathUtilsService, YangUtilsService, ParsingJsonService){
18 self.parametrizedPath = null;
21 self.receivedData = null;
23 self.availability = false;
26 self.selected = false;
29 self.getIdentifiers = getIdentifiers;
30 self.refresh = refresh;
33 self.clonePathArray = clonePathArray;
34 self.setParametrizedPath = setParametrizedPath;
35 self.getLastPathDataElemName = getLastPathDataElemName;
36 self.setDataForView = setDataForView;
37 self.clearParametrizedData = clearParametrizedData;
38 self.copyWithParametrizationAsNatural = copyWithParametrizationAsNatural;
39 self.setData = setData;
48 * @param parametrizedPath
55 function setData(sentData, receivedData, status, path, parametrizedPath, operation, api, name, collection,
58 self.sentData = sentData === null || sentData === undefined || $.isEmptyObject(sentData) ? null : sentData;
61 self.parametrizedPath = parametrizedPath;
62 self.method = operation;
64 self.receivedData = receivedData === null || receivedData === undefined || $.isEmptyObject(receivedData) ?
68 self.availability = (api !== null);
69 self.collection = collection;
70 self.timestamp = timestamp;
77 function getIdentifiers() {
80 self.api.pathArray.forEach(function (elem) {
81 elem.identifiers.forEach(function (i) {
90 * Refresh each element using getApiFunction
91 * @param getApiFunction
93 function refresh(getApiFunction) {
94 var refreshedApi = getApiFunction(self.path);
96 self.api = refreshedApi;
97 self.availability = (refreshedApi !== null);
107 * parametrizedPath: *,
116 sentData: self.sentData,
117 receivedData: self.receivedData,
119 collection: self.collection,
120 parametrizedPath: self.parametrizedPath,
124 timestamp: self.timestamp,
133 function clonePathArray() {
134 if ( self.api && self.api.pathArray ) {
135 self.api.clonedPathArray = self.api.pathArray.map(function (pe) {
139 self.api.clonedPathArray = [];
143 function setParametrizedPath(){
144 self.clonePathArray();
145 PathUtilsService.fillPath(self.api.clonedPathArray, self.parametrizedPath);
152 function getLastPathDataElemName() {
153 var pathArray = self.path.split(':');
154 return pathArray[pathArray.length - 1];
163 function setDataForView(sent, data){
167 angular.copy(data, newData);
168 parsedData = JSON.stringify(
169 YangUtilsService.stripAngularGarbage(newData, self.getLastPathDataElemName()), null, 4);
171 if ( sent && self.api ) {
172 if ( self.parametrizedPath ) {
173 self.setParametrizedPath();
175 self.clonePathArray();
182 function clearParametrizedData() {
183 self.parametrizedPath = null;
184 self.clonePathArray();
189 * @returns {HistoryRequest}
192 var result = new HistoryRequestModel(PathUtilsService, YangUtilsService, ParsingJsonService);
193 result.setData(self.sentData, self.receivedData, self.status, self.path,
194 self.parametrizedPath, self.method, self.api, self.name, self.collection, self.timestamp);
200 * @param parametrizedPath
201 * @param getApiFunction
203 * @param JSONparsingErrorClbk
206 function copyWithParametrizationAsNatural(parametrizedPath, getApiFunction, dataForView,
207 JSONparsingErrorClbk){
209 var parsedJsonObj = null,
212 parsedJsonObj = ParsingJsonService.parseJson(dataForView, JSONparsingErrorClbk);
215 result = new HistoryRequestModel(PathUtilsService, YangUtilsService, ParsingJsonService);
216 result.setData(parsedJsonObj, self.receivedData, self.status, parametrizedPath, '', self.method,
217 (getApiFunction || angular.noop)(result.path), self.name, self.collection, self.timestamp);
225 return HistoryRequestModel;