@singularsystems/neo-core 1.0.0-beta.2 → 1.0.0-beta.3

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.
@@ -82,7 +82,7 @@ export interface IPageManager {
82
82
  /**
83
83
  * Refresh the data only if the page manager has initialised.
84
84
  */
85
- invalidateData(taskRunner?: ITaskRunner): Promise<void>;
85
+ invalidateData(): void;
86
86
  /**
87
87
  * Refresh the data by calling the api endpoint with the current criteria.
88
88
  * This will not reset the page index, and will not update the total record count, therefore should only be called if your criteria has not changed since the last full fetch using refreshData().
@@ -101,6 +101,7 @@ export declare class PageManager<TCriteria extends ValueObject, TModel extends I
101
101
  private _totalRecords;
102
102
  private currentData;
103
103
  private initialFetchState;
104
+ private isInvalidated;
104
105
  /**
105
106
  * Gets or sets the criteria.
106
107
  */
@@ -125,6 +126,8 @@ export declare class PageManager<TCriteria extends ValueObject, TModel extends I
125
126
  * Called by the pager component on first display. Will fetch data if options.fetchInitial is set to true.
126
127
  */
127
128
  initialise(): void;
129
+ /** Called after a bound ui component has rendered. Used to refetch data if invalidateData() was called. */
130
+ afterRender(): void;
128
131
  /**
129
132
  * Refresh the data by calling the api endpoint with the current criteria.
130
133
  * Note: the page index will be reset to zero. Use this when your criteria has changed
@@ -133,9 +136,9 @@ export declare class PageManager<TCriteria extends ValueObject, TModel extends I
133
136
  */
134
137
  refreshData(getCount?: boolean, taskRunner?: ITaskRunner): Promise<void>;
135
138
  /**
136
- * Refresh the data only if the page manager has initialised.
139
+ * Refresh the data only if the page manager has initialised, and is currently being rendered.
137
140
  */
138
- invalidateData(taskRunner?: ITaskRunner): Promise<void>;
141
+ invalidateData(): void;
139
142
  /**
140
143
  * Refresh the data by calling the api endpoint with the current criteria.
141
144
  * This will not reset the page index, and will not update the total record count, therefore should only be called if your criteria has not changed since the last full fetch using refreshData().
@@ -144,6 +147,10 @@ export declare class PageManager<TCriteria extends ValueObject, TModel extends I
144
147
  refreshPage(taskRunner?: ITaskRunner): Promise<void>;
145
148
  private fetchAndSetData;
146
149
  setData(pageRecords: PartialPlainObject<TModel>[], totalRecords?: number): Promise<void>;
150
+ /**
151
+ * Adds an item to the current page, and increments the total record count.
152
+ */
153
+ addRecord(item: TModel | Model.PlainObject<TModel>): void;
147
154
  /**
148
155
  * Resets the page manager to its initial state and clears the current data.
149
156
  */
@@ -16,6 +16,7 @@ export var PageManager = /** @class */ (function (_super) {
16
16
  _this._totalRecords = -1;
17
17
  _this.currentData = new List(_this.modelType);
18
18
  _this.initialFetchState = "none";
19
+ _this.isInvalidated = false;
19
20
  _this.options = options || {};
20
21
  _this.allowSort = _this.options.allowSort !== false;
21
22
  _this.performsRemoteSorting = true;
@@ -59,6 +60,7 @@ export var PageManager = /** @class */ (function (_super) {
59
60
  if (this.initialFetchState === "loading") {
60
61
  return null;
61
62
  }
63
+ void this.isInvalidated;
62
64
  return this.initialFetchState === "complete";
63
65
  },
64
66
  enumerable: false,
@@ -126,10 +128,21 @@ export var PageManager = /** @class */ (function (_super) {
126
128
  PageManager.prototype.initialise = function () {
127
129
  if (!this.hasInitialised) {
128
130
  this.hasInitialised = true;
131
+ this.isInvalidated = false;
129
132
  if (this.options.fetchInitial) {
130
133
  this.refreshData(true, this.options.initialTaskRunner);
131
134
  }
132
135
  }
136
+ else {
137
+ this.afterRender();
138
+ }
139
+ };
140
+ /** Called after a bound ui component has rendered. Used to refetch data if invalidateData() was called. */
141
+ PageManager.prototype.afterRender = function () {
142
+ if (this.isInvalidated) {
143
+ this.isInvalidated = false;
144
+ this.refreshPage();
145
+ }
133
146
  };
134
147
  /**
135
148
  * Refresh the data by calling the api endpoint with the current criteria.
@@ -167,22 +180,12 @@ export var PageManager = /** @class */ (function (_super) {
167
180
  });
168
181
  };
169
182
  /**
170
- * Refresh the data only if the page manager has initialised.
183
+ * Refresh the data only if the page manager has initialised, and is currently being rendered.
171
184
  */
172
- PageManager.prototype.invalidateData = function (taskRunner) {
173
- return __awaiter(this, void 0, void 0, function () {
174
- return __generator(this, function (_a) {
175
- switch (_a.label) {
176
- case 0:
177
- if (!this.hasInitialised) return [3 /*break*/, 2];
178
- return [4 /*yield*/, this.refreshData(true, taskRunner)];
179
- case 1:
180
- _a.sent();
181
- _a.label = 2;
182
- case 2: return [2 /*return*/];
183
- }
184
- });
185
- });
185
+ PageManager.prototype.invalidateData = function () {
186
+ if (this.hasInitialised) {
187
+ this.isInvalidated = true;
188
+ }
186
189
  };
187
190
  /**
188
191
  * Refresh the data by calling the api endpoint with the current criteria.
@@ -254,6 +257,18 @@ export var PageManager = /** @class */ (function (_super) {
254
257
  });
255
258
  });
256
259
  };
260
+ /**
261
+ * Adds an item to the current page, and increments the total record count.
262
+ */
263
+ PageManager.prototype.addRecord = function (item) {
264
+ this._totalRecords += 1;
265
+ if (item.meta) {
266
+ this.data.push(item);
267
+ }
268
+ else {
269
+ this.data.push(this.modelType.fromJSObject(item));
270
+ }
271
+ };
257
272
  /**
258
273
  * Resets the page manager to its initial state and clears the current data.
259
274
  */
@@ -345,6 +360,10 @@ export var PageManager = /** @class */ (function (_super) {
345
360
  Observable(),
346
361
  __metadata("design:type", String)
347
362
  ], PageManager.prototype, "initialFetchState", void 0);
363
+ __decorate([
364
+ Observable(),
365
+ __metadata("design:type", Object)
366
+ ], PageManager.prototype, "isInvalidated", void 0);
348
367
  PageManager = __decorate([
349
368
  NeoModel,
350
369
  __metadata("design:paramtypes", [Object, Function, Function, Object])
@@ -88,7 +88,12 @@ Array.prototype.sortBy = function (valueFnOrKey, direction, dataType) {
88
88
  }
89
89
  };
90
90
  }
91
- return this.sort(comparer);
91
+ var array = this;
92
+ if (this.addNew) {
93
+ // Mobx6 doesn't allow the array to be sorted in place, must create a new one.
94
+ array = this.slice();
95
+ }
96
+ return array.sort(comparer);
92
97
  };
93
98
  Array.prototype.remove = function (item) {
94
99
  var index = this.indexOf(item);
@@ -1,7 +1,8 @@
1
- import { __decorate, __extends } from "tslib";
1
+ import { __decorate, __extends, __metadata } from "tslib";
2
2
  import ValueObject from '../ValueObject';
3
+ import { Date as DateAttribute } from '../Decorators';
3
4
  import NeoModel from '../NeoModel';
4
- var UserEventBase = /** @class */ (function (_super) {
5
+ export var UserEventBase = /** @class */ (function (_super) {
5
6
  __extends(UserEventBase, _super);
6
7
  function UserEventBase() {
7
8
  var _this = _super !== null && _super.apply(this, arguments) || this;
@@ -16,9 +17,12 @@ var UserEventBase = /** @class */ (function (_super) {
16
17
  enumerable: false,
17
18
  configurable: true
18
19
  });
20
+ __decorate([
21
+ DateAttribute(),
22
+ __metadata("design:type", Object)
23
+ ], UserEventBase.prototype, "on", void 0);
19
24
  return UserEventBase;
20
25
  }(ValueObject));
21
- export { UserEventBase };
22
26
  export var UserEvent = /** @class */ (function (_super) {
23
27
  __extends(UserEvent, _super);
24
28
  function UserEvent() {
@@ -20,6 +20,8 @@ export declare const Settings: {
20
20
  collapsed: any;
21
21
  sortAsc: any;
22
22
  sortDesc: any;
23
+ /** Icon used in back buttons */
24
+ backIcon: any;
23
25
  };
24
26
  /** Grid default settings */
25
27
  grid: {
package/dist/Settings.js CHANGED
@@ -19,6 +19,8 @@ export var Settings = {
19
19
  collapsed: "far-plus-square",
20
20
  sortAsc: "sort-up",
21
21
  sortDesc: "sort-down",
22
+ /** Icon used in back buttons */
23
+ backIcon: "arrow-left",
22
24
  },
23
25
  /** Grid default settings */
24
26
  grid: {
package/dist/Utils.d.ts CHANGED
@@ -61,6 +61,10 @@ export declare class Utils {
61
61
  * Converts a string like 'user' to 'fa fa-user' or 'fa-user' to 'fa fa-user' or 'far-user' to 'far fa-user'
62
62
  */
63
63
  static getFontAwesomeClass(faString: string): string;
64
+ static getFontAwesomeIconProps(faString: string): {
65
+ name: string;
66
+ isSolid: boolean | undefined;
67
+ };
64
68
  /** Concatenates an array of strings together, putting spaces in-between them. */
65
69
  static joinWithSpaces(arg0?: string, ...args: (string | undefined)[]): string;
66
70
  /**
package/dist/Utils.js CHANGED
@@ -116,15 +116,23 @@ var Utils = /** @class */ (function () {
116
116
  * Converts a string like 'user' to 'fa fa-user' or 'fa-user' to 'fa fa-user' or 'far-user' to 'far fa-user'
117
117
  */
118
118
  Utils.getFontAwesomeClass = function (faString) {
119
- var isRegular = false;
119
+ var props = this.getFontAwesomeIconProps(faString);
120
+ return (props.isSolid === false ? 'far ' : (props.isSolid === true ? 'fas ' : 'fa ')) + 'fa-' + props.name;
121
+ };
122
+ Utils.getFontAwesomeIconProps = function (faString) {
123
+ var isSolid;
120
124
  if (faString.indexOf("fa-") === 0) {
121
125
  faString = faString.substring(3);
122
126
  }
123
127
  else if (faString.indexOf("far-") === 0) {
124
- isRegular = true;
128
+ isSolid = false;
129
+ faString = faString.substring(4);
130
+ }
131
+ else if (faString.indexOf("fas-") === 0) {
132
+ isSolid = true;
125
133
  faString = faString.substring(4);
126
134
  }
127
- return (isRegular ? 'far ' : 'fa ') + 'fa-' + faString;
135
+ return { name: faString, isSolid: isSolid };
128
136
  };
129
137
  /** Concatenates an array of strings together, putting spaces in-between them. */
130
138
  Utils.joinWithSpaces = function (arg0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularsystems/neo-core",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.3",
4
4
  "description": "Core functionality for the Neo client library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",