@gudhub/core 1.0.46 → 1.0.49

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.
@@ -107,19 +107,23 @@ export class FileManager {
107
107
  }
108
108
  }
109
109
 
110
- addFileToStorage(app_id, file) {
110
+ addFileToStorage(app_id, element_id, file) {
111
111
  const app = this.storage.getApp(app_id);
112
112
  if (app) {
113
113
  app.file_list.push(file);
114
114
  this.storage.updateApp(app);
115
+ this.pipeService.emit("gh_file_upload", { app_id, item_id: file.item_id, element_id }, file);
115
116
  }
116
117
  }
117
118
 
118
- addFilesToStorage(app_id, files) {
119
+ addFilesToStorage(app_id, element_id, files) {
119
120
  const app = this.storage.getApp(app_id);
120
121
  if (app) {
121
122
  app.file_list.push(...files);
122
123
  this.storage.updateApp(app);
124
+ files.forEach(file => {
125
+ this.pipeService.emit("gh_file_upload", { app_id, item_id: file.item_id, element_id }, file);
126
+ });
123
127
  }
124
128
  }
125
129
 
@@ -190,7 +194,7 @@ async getFiles(app_id, filesId = []) {
190
194
 
191
195
  async uploadFileFromString(fileObject) {
192
196
  const file = await this.uploadFileFromStringApi(fileObject);
193
- this.addFileToStorage(file.app_id, file);
197
+ this.addFileToStorage(file.app_id, fileObject.element_id, file);
194
198
  return file;
195
199
  }
196
200
 
@@ -9,7 +9,7 @@ import {
9
9
  import { group } from "./filter/group.js";
10
10
  import { searchValue } from "./filter/utils.js";
11
11
  import populateItems from "./populate_items/populate_items.js";
12
- import { populateWithDate, getDate } from "./get_date/get_date.js";
12
+ import { populateWithDate, getDate, checkRecurringDate } from "./get_date/get_date.js";
13
13
  import { mergeObjects } from "./merge_objects/merge_objects.js";
14
14
  import { mergeChunks } from "./merge_chunks/merge_chunks.js";
15
15
  import { getInterpretedValue } from "./interpretation/interpretation.js";
@@ -85,6 +85,10 @@ export class Utils {
85
85
  return getDate(queryKey);
86
86
  }
87
87
 
88
+ checkRecurringDate(date, option) {
89
+ return checkRecurringDate(date, option);
90
+ }
91
+
88
92
  populateItems(items, model, keep_data) {
89
93
  return populateItems(items, model, keep_data);
90
94
  }
@@ -171,6 +171,13 @@ class Checker {
171
171
  );
172
172
  };
173
173
  break;
174
+ case "recurring_date":
175
+ this._checkFn = function (data, filtersValues) {
176
+ return filtersValues.some((_filter) =>
177
+ data.some((_dataItem) => gudhub.checkRecurringDate(_dataItem, _filter))
178
+ );
179
+ };
180
+ break;
174
181
  }
175
182
  return this;
176
183
  }
@@ -236,6 +243,16 @@ class BooleanFetchStrategy {
236
243
  }
237
244
  }
238
245
 
246
+ class RecurringDateStrategy {
247
+ convert(val) {
248
+ return [Number(val)];
249
+ }
250
+
251
+ convertFilterValue(val) {
252
+ return String(val);
253
+ }
254
+ }
255
+
239
256
  class Aggregate {
240
257
  constructor() {
241
258
  this._strategies = {
@@ -244,6 +261,7 @@ class Aggregate {
244
261
  booleanStrategy: new BooleanFetchStrategy(),
245
262
  rangeStrategy: new RangeFetchStrategy(),
246
263
  dateStrategy: new dateFetchStrategy(),
264
+ recurringDateStrategy: new RecurringDateStrategy()
247
265
  };
248
266
  }
249
267
 
@@ -277,6 +295,8 @@ class Aggregate {
277
295
  case "value":
278
296
  this._currentStrategy = this._strategies.booleanStrategy;
279
297
  break;
298
+ case "recurring_date":
299
+ this._currentStrategy = this._strategies.recurringDateStrategy
280
300
  }
281
301
  return this;
282
302
  }
@@ -88,3 +88,45 @@ export function getDate(queryKey) {
88
88
  return date.getTime();
89
89
  }
90
90
  }
91
+
92
+ //********************** CHECK RECURRING DATE ************************//
93
+
94
+ export function checkRecurringDate(date, option) {
95
+
96
+ date = new Date(date);
97
+
98
+ let currentDate = new Date();
99
+
100
+ switch (option) {
101
+ case 'day':
102
+ if(date.getDate() + '.' + date.getMonth() === currentDate.getDate() + '.' + date.getMonth()) {
103
+ return true;
104
+ } else {
105
+ return false;
106
+ }
107
+ case 'week':
108
+ if(getWeek(currentDate) === getWeek(date)) {
109
+ return true;
110
+ } else {
111
+ return false;
112
+ }
113
+ case 'month':
114
+ if(date.getMonth() === currentDate.getMonth()) {
115
+ return true;
116
+ } else {
117
+ return false;
118
+ }
119
+ default:
120
+ return true;
121
+ }
122
+
123
+ function getWeek(date) {
124
+ let d = new Date(date.getFullYear(), date.getMonth(), date.getDate());
125
+ let dayNumber = d.getDay();
126
+ d.setDate(d.getDate() + 4 - dayNumber);
127
+ let firstJanuary = new Date(date.getFullYear(), 0, 1);
128
+ let weekNumber = Math.ceil((((d- firstJanuary) / 86400000) + 1) / 7);
129
+ return weekNumber;
130
+ }
131
+
132
+ }
@@ -50,4 +50,37 @@ describe("GET DATE", function () {
50
50
  let day = gudhub.getDate('this_saturday');
51
51
  day.getDay().should.equal(6);
52
52
  });
53
+
54
+ it("CHECK IF DATE TODAY", function() {
55
+ let today = new Date();
56
+ let result = gudhub.checkRecurringDate(today, 'day');
57
+ result.should.equal(true);
58
+
59
+ let tommorow = new Date();
60
+ tommorow.setDate(tommorow.getDate() + 1);
61
+ result = gudhub.checkRecurringDate(tommorow, 'day');
62
+ result.should.equal(false);
63
+ })
64
+
65
+ it("CHECK IF DATE IN THIS WEEK", function() {
66
+ let today = new Date();
67
+ let result = gudhub.checkRecurringDate(today, 'week');
68
+ result.should.equal(true);
69
+
70
+ let twoWeeksLater = new Date();
71
+ twoWeeksLater.setDate(twoWeeksLater.getDate() + 14);
72
+ result = gudhub.checkRecurringDate(twoWeeksLater, 'week');
73
+ result.should.equal(false);
74
+ });
75
+
76
+ it("CHECK IF DATE IN THIS MONTH", function() {
77
+ let today = new Date();
78
+ let result = gudhub.checkRecurringDate(today, 'month');
79
+ result.should.equal(true);
80
+
81
+ let twoMonthsLater = new Date();
82
+ twoMonthsLater.setDate(twoMonthsLater.getDate() + 60);
83
+ result = gudhub.checkRecurringDate(twoMonthsLater, 'month');
84
+ result.should.equal(false);
85
+ });
53
86
  });
package/GUDHUB/gudhub.js CHANGED
@@ -178,6 +178,10 @@ export class GudHub {
178
178
  return this.util.populateWithDate(items, model);
179
179
  }
180
180
 
181
+ checkRecurringDate(date, option) {
182
+ return this.util.checkRecurringDate(date, option);
183
+ }
184
+
181
185
  populateItems(items, model, keep_data) {
182
186
  return this.util.populateItems(items, model, keep_data);
183
187
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.0.46",
3
+ "version": "1.0.49",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {