@flumens/models 0.6.0 → 0.7.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.
@@ -1,4 +1,4 @@
1
- import Model, { Attrs as AttrsOriginal, Options as OptionsOriginal } from '../Model';
1
+ import Model, { Data as DataOriginal, Options as OptionsOriginal } from '../Model';
2
2
  import Occurrence from './Occurrence';
3
3
  import Sample from './Sample';
4
4
  export interface Metadata {
@@ -8,7 +8,7 @@ export type URL = string;
8
8
  export interface Options<T = any, S = any> extends OptionsOriginal<T> {
9
9
  metadata?: S;
10
10
  }
11
- export interface Attrs extends AttrsOriginal {
11
+ export interface Data extends DataOriginal {
12
12
  type?: string;
13
13
  data?: any;
14
14
  thumbnail?: DataURI;
@@ -24,8 +24,7 @@ export interface Remote {
24
24
  headers?: any;
25
25
  timeout?: number;
26
26
  }
27
- declare class Media<T extends Attrs = Attrs, S extends Metadata = Metadata> extends Model {
28
- static fromJSON(json: any): Media<Attrs, Metadata>;
27
+ declare class Media<T extends Data = Data, S extends Metadata = Metadata> extends Model<T> {
29
28
  /**
30
29
  * Transforms and resizes an image file into a string.
31
30
  * Can accept file image path and a file input file.
@@ -53,7 +52,6 @@ declare class Media<T extends Attrs = Attrs, S extends Metadata = Metadata> exte
53
52
  * @returns
54
53
  */
55
54
  static getImageModel(imageURL: URL, dataDirPath: string, skipThumbnail?: boolean): Promise<Media>;
56
- attrs: T;
57
55
  metadata: S;
58
56
  remote: Remote;
59
57
  debouncedValue: number;
@@ -82,7 +80,7 @@ declare class Media<T extends Attrs = Attrs, S extends Metadata = Metadata> exte
82
80
  width?: number;
83
81
  height?: number;
84
82
  }): Promise<void>;
85
- isUploaded(): boolean;
86
- isDisabled(): boolean;
83
+ get isUploaded(): boolean;
84
+ get isDisabled(): boolean;
87
85
  }
88
86
  export default Media;
@@ -1,369 +1 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var tslib = require('tslib');
6
- var mobx = require('mobx');
7
- var axios = require('axios');
8
- var utils = require('@flumens/utils');
9
- var Model = require('../Model.js');
10
- var helpers = require('./helpers.js');
11
-
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
-
14
- var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
15
-
16
- var THUMBNAIL_WIDTH = 100; // px
17
- var THUMBNAIL_HEIGHT = 100; // px
18
- var isHybrid = utils.isPlatform('hybrid');
19
- var Media = /** @class */ (function (_super) {
20
- tslib.__extends(Media, _super);
21
- function Media(_a) {
22
- if (_a === void 0) { _a = {}; }
23
- var _this = this;
24
- var _b = _a.metadata, metadata = _b === void 0 ? {} : _b, options = tslib.__rest(_a, ["metadata"]);
25
- _this = _super.call(this, options) || this;
26
- _this.remote = {
27
- synchronising: false,
28
- url: null, // must be set up for remote sync
29
- headers: {}, // auth and other headers
30
- timeout: 120000, // 120s
31
- };
32
- _this.debouncedValue = 300;
33
- _this.parent = _this.parent;
34
- _this.metadata = mobx.observable(metadata);
35
- return _this;
36
- }
37
- Media.fromJSON = function (json) {
38
- var _a, _b, _c;
39
- return new this(tslib.__assign(tslib.__assign({}, json), { createdAt: json.createdAt || ((_a = json.metadata) === null || _a === void 0 ? void 0 : _a.createdOn), updatedAt: json.updatedAt || ((_b = json.metadata) === null || _b === void 0 ? void 0 : _b.updatedOn), syncedAt: json.syncedAt || ((_c = json.metadata) === null || _c === void 0 ? void 0 : _c.syncedOn) }));
40
- };
41
- /**
42
- * Transforms and resizes an image file into a string.
43
- * Can accept file image path and a file input file.
44
- *
45
- * @param onError
46
- * @param file
47
- * @param onSaveSuccess
48
- * @returns {number}
49
- */
50
- Media.getDataURI = function (file, options) {
51
- if (options === void 0) { options = {}; }
52
- var promise = new Promise(function (fulfill, reject) {
53
- // file paths
54
- if (typeof file === 'string') {
55
- // get extension
56
- var fileType_1 = file.replace(/.*\.([a-z]+)$/i, '$1');
57
- if (fileType_1 === 'jpg')
58
- fileType_1 = 'jpeg'; // to match media types image/jpeg
59
- Media.resize(file, fileType_1, options.width, options.height).then(function (args) {
60
- var image = args[0], dataURI = args[1];
61
- fulfill([dataURI, fileType_1, image.width, image.height]);
62
- });
63
- return;
64
- }
65
- // file inputs
66
- if (!window.FileReader) {
67
- reject(new Error('No File Reader'));
68
- return;
69
- }
70
- var reader = new FileReader();
71
- reader.onload = function (event) {
72
- var _a, _b;
73
- if (options.width || options.height) {
74
- // resize
75
- Media.resize((_a = event.target) === null || _a === void 0 ? void 0 : _a.result, file.type, options.width, options.height).then(function (args) {
76
- var image = args[0], dataURI = args[1];
77
- fulfill([dataURI, file.type, image.width, image.height]);
78
- });
79
- }
80
- else {
81
- var image_1 = new window.Image(); // native one
82
- image_1.onload = function () {
83
- var _a;
84
- var type = file.type.replace(/.*\/([a-z]+)$/i, '$1');
85
- fulfill([(_a = event.target) === null || _a === void 0 ? void 0 : _a.result, type, image_1.width, image_1.height]);
86
- };
87
- image_1.src = (_b = event.target) === null || _b === void 0 ? void 0 : _b.result;
88
- }
89
- };
90
- reader.readAsDataURL(file);
91
- });
92
- return promise;
93
- };
94
- /**
95
- * http://stackoverflow.com/questions/2516117/how-to-scale-an-image-in-data-uri-format-in-javascript-real-scaling-not-usin
96
- */
97
- Media.resize = function (data, fileType, MAX_WIDTH, MAX_HEIGHT) {
98
- var promise = new Promise(function (fulfill) {
99
- var image = new window.Image(); // native one
100
- image.onload = function () {
101
- var _a;
102
- var width = image.width;
103
- var height = image.height;
104
- var maxWidth = !MAX_WIDTH || MAX_WIDTH > width ? width : MAX_WIDTH;
105
- var maxHeight = !MAX_HEIGHT || MAX_HEIGHT > height ? height : MAX_HEIGHT;
106
- var res = null;
107
- // resizing
108
- if (width > height) {
109
- res = width / maxWidth;
110
- }
111
- else {
112
- res = height / maxHeight;
113
- }
114
- width /= res;
115
- height /= res;
116
- // Create a canvas with the desired dimensions
117
- var canvas = document.createElement('canvas');
118
- canvas.width = width;
119
- canvas.height = height;
120
- // Scale and draw the source image to the canvas
121
- (_a = canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.drawImage(image, 0, 0, width, height);
122
- // Convert the canvas to a data URL in some format
123
- fulfill([image, canvas.toDataURL(fileType)]);
124
- };
125
- image.src = data;
126
- });
127
- return promise;
128
- };
129
- /**
130
- * Create new image model with a photo
131
- * @param ImageModel Class representing the model.
132
- * @param imageURL
133
- * @param dataDirPath
134
- * @returns
135
- */
136
- Media.getImageModel = function (imageURL, dataDirPath, skipThumbnail) {
137
- return tslib.__awaiter(this, void 0, void 0, function () {
138
- var MediaClass, width, height, data, image, imageModel;
139
- var _a;
140
- return tslib.__generator(this, function (_b) {
141
- switch (_b.label) {
142
- case 0:
143
- MediaClass = this;
144
- if (!imageURL) {
145
- throw new Error('File not found while creating image model.');
146
- }
147
- if (!isHybrid) return [3 /*break*/, 2];
148
- return [4 /*yield*/, utils.createImage(imageURL)];
149
- case 1:
150
- image = _b.sent();
151
- width = image.width;
152
- height = image.height;
153
- data = imageURL.split('/').pop();
154
- return [3 /*break*/, 4];
155
- case 2: return [4 /*yield*/, MediaClass.getDataURI(imageURL, {
156
- width: 2000,
157
- height: 2000,
158
- })];
159
- case 3:
160
- _a = _b.sent(), data = _a[0], width = _a[2], height = _a[3];
161
- _b.label = 4;
162
- case 4:
163
- imageModel = new MediaClass({
164
- attrs: {
165
- data: data,
166
- type: 'jpeg',
167
- width: width,
168
- height: height,
169
- path: dataDirPath,
170
- },
171
- });
172
- if (!!skipThumbnail) return [3 /*break*/, 6];
173
- return [4 /*yield*/, imageModel.addThumbnail()];
174
- case 5:
175
- _b.sent();
176
- _b.label = 6;
177
- case 6: return [2 /*return*/, imageModel];
178
- }
179
- });
180
- });
181
- };
182
- Media.prototype.toJSON = function () {
183
- var data = _super.prototype.toJSON.call(this);
184
- return JSON.parse(JSON.stringify(tslib.__assign(tslib.__assign({}, data), { metadata: mobx.toJS(this.metadata) || {} })));
185
- };
186
- Media.prototype.setupdatedAtTimestamp = function (newUpdatedAt) {
187
- var _a;
188
- _super.prototype.setUpdatedAtTimestamp.call(this, newUpdatedAt);
189
- (_a = this.parent) === null || _a === void 0 ? void 0 : _a.setUpdatedAtTimestamp(newUpdatedAt);
190
- };
191
- Media.prototype.getSubmission = function (warehouseMediaNames) {
192
- if (warehouseMediaNames === void 0) { warehouseMediaNames = {}; }
193
- var queued = warehouseMediaNames[this.cid];
194
- if (!this.id && !queued) {
195
- throw new Error('Image ID or queued ID is missing.');
196
- }
197
- var submission = {
198
- values: {
199
- caption: this.attrs.caption,
200
- },
201
- };
202
- if (this.id) {
203
- submission.values.id = this.id;
204
- }
205
- else {
206
- submission.values.queued = queued.name;
207
- }
208
- return submission;
209
- };
210
- Media.prototype.sync = function () {
211
- return tslib.__awaiter(this, void 0, void 0, function () {
212
- return tslib.__generator(this, function (_a) {
213
- return [2 /*return*/, this.parent ? this.parent.sync() : _super.prototype.sync.call(this)];
214
- });
215
- });
216
- };
217
- Media.prototype.uploadFile = function () {
218
- return tslib.__awaiter(this, arguments, void 0, function (force) {
219
- var twelveHrsAgo, alreadySynced, formData, data, headers, _a, res;
220
- var _b;
221
- var _c;
222
- if (force === void 0) { force = false; }
223
- return tslib.__generator(this, function (_d) {
224
- switch (_d.label) {
225
- case 0:
226
- if (this.id) {
227
- throw new Error('A file of a media on the remote cannot be uploaded again.');
228
- }
229
- twelveHrsAgo = Date.now() - 1000 * 60 * 60 * 12;
230
- alreadySynced = this.syncedAt > twelveHrsAgo && this.attrs.queued;
231
- if (!force && alreadySynced)
232
- return [2 /*return*/];
233
- return [4 /*yield*/, this.getFormData()];
234
- case 1:
235
- formData = _d.sent();
236
- data = new FormData();
237
- (_b = data).append.apply(_b, formData);
238
- if (!(typeof this.remote.headers === 'function')) return [3 /*break*/, 3];
239
- return [4 /*yield*/, this.remote.headers()];
240
- case 2:
241
- _a = _d.sent();
242
- return [3 /*break*/, 4];
243
- case 3:
244
- _a = this.remote.headers;
245
- _d.label = 4;
246
- case 4:
247
- headers = _a;
248
- return [4 /*yield*/, axios__default["default"].post("".concat(this.remote.url, "/media-queue"), data, {
249
- headers: headers,
250
- timeout: 120000,
251
- })];
252
- case 5:
253
- res = _d.sent();
254
- if (!((_c = res.data[this.cid]) === null || _c === void 0 ? void 0 : _c.name))
255
- throw new Error('New remote media name was not be found.');
256
- this.attrs.queued = res.data[this.cid].name;
257
- this.syncedAt = new Date().getTime();
258
- return [2 /*return*/];
259
- }
260
- });
261
- });
262
- };
263
- Media.prototype.getFormData = function () {
264
- return tslib.__awaiter(this, void 0, void 0, function () {
265
- var type, extension, mediaType, url, blob, name;
266
- var _a;
267
- return tslib.__generator(this, function (_b) {
268
- switch (_b.label) {
269
- case 0:
270
- type = this.attrs.type;
271
- extension = type;
272
- mediaType = type;
273
- if (type === null || type === void 0 ? void 0 : type.match(/image.*/)) {
274
- _a = type.split('/'), extension = _a[1];
275
- }
276
- else {
277
- mediaType = "image/".concat(mediaType);
278
- }
279
- url = this.getURL();
280
- return [4 /*yield*/, helpers.getBlobFromURL(url, mediaType)];
281
- case 1:
282
- blob = _b.sent();
283
- name = this.cid;
284
- return [2 /*return*/, [name, blob, "".concat(name, ".").concat(extension)]];
285
- }
286
- });
287
- });
288
- };
289
- Media.prototype.getRemoteURL = function () {
290
- if (!this.remote.url) {
291
- throw new Error('No remote url was set.');
292
- }
293
- if (!this.attrs.queued && !this.attrs.path) {
294
- throw new Error('No media queued or path attribute.');
295
- }
296
- var baseRemoteURL = this.remote.url.replace('/index.php/services/rest', '');
297
- if (this.attrs.queued) {
298
- return "".concat(baseRemoteURL, "/upload-queue/").concat(this.attrs.queued);
299
- }
300
- return "".concat(baseRemoteURL, "/upload/").concat(this.attrs.path);
301
- };
302
- /**
303
- * Returns image's absolute URL or dataURI.
304
- */
305
- Media.prototype.getURL = function () {
306
- return this.attrs.data;
307
- };
308
- /**
309
- * Resizes itself.
310
- */
311
- Media.prototype.resize = function (MAX_WIDTH, MAX_HEIGHT) {
312
- var _this = this;
313
- var that = this;
314
- var promise = new Promise(function (fulfill, reject) {
315
- Media.resize(_this.getURL(), _this.attrs.type, MAX_WIDTH, MAX_HEIGHT)
316
- .then(function (args) {
317
- var image = args[0], data = args[1];
318
- that.attrs.data = data;
319
- fulfill([image, data]);
320
- })
321
- .catch(reject);
322
- });
323
- return promise;
324
- };
325
- /**
326
- * Adds a thumbnail to image model.
327
- * @param options
328
- */
329
- Media.prototype.addThumbnail = function (options) {
330
- var _this = this;
331
- var that = this;
332
- var promise = new Promise(function (fulfill, reject) {
333
- // check if data source is dataURI
334
- var re = /^data:/i;
335
- if (re.test(_this.getURL())) {
336
- Media.resize(_this.getURL(), _this.attrs.type, THUMBNAIL_WIDTH , THUMBNAIL_WIDTH )
337
- .then(function (args) {
338
- var data = args[1];
339
- that.attrs.thumbnail = data;
340
- fulfill();
341
- })
342
- .catch(reject);
343
- return;
344
- }
345
- Media.getDataURI(_this.getURL(), {
346
- width: THUMBNAIL_WIDTH ,
347
- height: THUMBNAIL_HEIGHT ,
348
- })
349
- .then(function (data) {
350
- that.attrs.thumbnail = data[0];
351
- fulfill();
352
- })
353
- .catch(reject);
354
- });
355
- return promise;
356
- };
357
- Media.prototype.isUploaded = function () {
358
- if (!this.parent) {
359
- throw new Error('No media parent to return disabled status.');
360
- }
361
- return this.parent.isUploaded();
362
- };
363
- Media.prototype.isDisabled = function () {
364
- return this.isUploaded();
365
- };
366
- return Media;
367
- }(Model["default"]));
368
-
369
- exports["default"] = Media;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),e=require("mobx"),a=require("axios"),r=require("@flumens/utils"),i=require("../Model.js"),n=require("./helpers.js");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var s=o(a),d=r.isPlatform("hybrid"),u=function(a){function i(r){void 0===r&&(r={});var i=this,n=r.metadata,o=void 0===n?{}:n,s=t.__rest(r,["metadata"]);return s.createdAt=s.createdAt||(null==o?void 0:o.createdOn),s.updatedAt=s.updatedAt||(null==o?void 0:o.updatedOn),s.syncedAt=s.syncedAt||(null==o?void 0:o.syncedOn),(i=a.call(this,s)||this).remote={synchronising:!1,url:null,headers:{},timeout:12e4},i.debouncedValue=300,i.parent=i.parent,i.metadata=e.observable(o),i}return t.__extends(i,a),i.getDataURI=function(t,e){return void 0===e&&(e={}),new Promise((function(a,r){if("string"==typeof t){var n=t.replace(/.*\.([a-z]+)$/i,"$1");return"jpg"===n&&(n="jpeg"),void i.resize(t,n,e.width,e.height).then((function(t){var e=t[0],r=t[1];a([r,n,e.width,e.height])}))}if(window.FileReader){var o=new FileReader;o.onload=function(r){var n,o;if(e.width||e.height)i.resize(null===(n=r.target)||void 0===n?void 0:n.result,t.type,e.width,e.height).then((function(e){var r=e[0],i=e[1];a([i,t.type,r.width,r.height])}));else{var s=new window.Image;s.onload=function(){var e,i=t.type.replace(/.*\/([a-z]+)$/i,"$1");a([null===(e=r.target)||void 0===e?void 0:e.result,i,s.width,s.height])},s.src=null===(o=r.target)||void 0===o?void 0:o.result}},o.readAsDataURL(t)}else r(new Error("No File Reader"))}))},i.resize=function(t,e,a,r){return new Promise((function(i){var n=new window.Image;n.onload=function(){var t,o=n.width,s=n.height,d=null;o/=d=o>s?o/(!a||a>o?o:a):s/(!r||r>s?s:r),s/=d;var u=document.createElement("canvas");u.width=o,u.height=s,null===(t=u.getContext("2d"))||void 0===t||t.drawImage(n,0,0,o,s),i([n,u.toDataURL(e)])},n.src=t}))},i.getImageModel=function(e,a,i){return t.__awaiter(this,void 0,void 0,(function(){var n,o,s,u,h,c,l;return t.__generator(this,(function(t){switch(t.label){case 0:if(n=this,!e)throw new Error("File not found while creating image model.");return d?[4,r.createImage(e)]:[3,2];case 1:return h=t.sent(),o=h.width,s=h.height,u=e.split("/").pop(),[3,4];case 2:return[4,n.getDataURI(e,{width:2e3,height:2e3})];case 3:l=t.sent(),u=l[0],o=l[2],s=l[3],t.label=4;case 4:return c=new n({data:{data:u,type:"jpeg",width:o,height:s,path:a}}),i?[3,6]:[4,c.addThumbnail()];case 5:t.sent(),t.label=6;case 6:return[2,c]}}))}))},i.prototype.toJSON=function(){var r=a.prototype.toJSON.call(this);return JSON.parse(JSON.stringify(t.__assign(t.__assign({},r),{metadata:e.toJS(this.metadata)||{}})))},i.prototype.setupdatedAtTimestamp=function(t){var e;a.prototype.setUpdatedAtTimestamp.call(this,t),null===(e=this.parent)||void 0===e||e.setUpdatedAtTimestamp(t)},i.prototype.getSubmission=function(t){void 0===t&&(t={});var e=t[this.cid];if(!this.id&&!e)throw new Error("Image ID or queued ID is missing.");var a={values:{caption:this.data.caption}};return this.id?a.values.id=this.id:a.values.queued=e.name,a},i.prototype.sync=function(){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(t){return[2,this.parent?this.parent.sync():a.prototype.sync.call(this)]}))}))},i.prototype.uploadFile=function(){return t.__awaiter(this,arguments,void 0,(function(e){var a,r,i,n,o,d,u,h,c;return void 0===e&&(e=!1),t.__generator(this,(function(t){switch(t.label){case 0:if(this.id)throw new Error("A file of a media on the remote cannot be uploaded again.");return a=Date.now()-432e5,r=this.syncedAt>a&&this.data.queued,!e&&r?[2]:[4,this.getFormData()];case 1:return i=t.sent(),n=new FormData,(h=n).append.apply(h,i),"function"!=typeof this.remote.headers?[3,3]:[4,this.remote.headers()];case 2:return d=t.sent(),[3,4];case 3:d=this.remote.headers,t.label=4;case 4:return o=d,[4,s.default.post("".concat(this.remote.url,"/media-queue"),n,{headers:o,timeout:12e4})];case 5:if(u=t.sent(),!(null===(c=u.data[this.cid])||void 0===c?void 0:c.name))throw new Error("New remote media name was not be found.");return this.data.queued=u.data[this.cid].name,this.syncedAt=(new Date).getTime(),[2]}}))}))},i.prototype.getFormData=function(){return t.__awaiter(this,void 0,void 0,(function(){var e,a,r,i,o,s,d;return t.__generator(this,(function(t){switch(t.label){case 0:return e=this.data.type,a=e,r=e,(null==e?void 0:e.match(/image.*/))?(d=e.split("/"),a=d[1]):r="image/".concat(r),i=this.getURL(),[4,n.getBlobFromURL(i,r)];case 1:return o=t.sent(),[2,[s=this.cid,o,"".concat(s,".").concat(a)]]}}))}))},i.prototype.getRemoteURL=function(){if(!this.remote.url)throw new Error("No remote url was set.");if(!this.data.queued&&!this.data.path)throw new Error("No media queued or path attribute.");var t=this.remote.url.replace("/index.php/services/rest","");return this.data.queued?"".concat(t,"/upload-queue/").concat(this.data.queued):"".concat(t,"/upload/").concat(this.data.path)},i.prototype.getURL=function(){return this.data.data},i.prototype.resize=function(t,e){var a=this,r=this;return new Promise((function(n,o){i.resize(a.getURL(),a.data.type,t,e).then((function(t){var e=t[0],a=t[1];r.data.data=a,n([e,a])})).catch(o)}))},i.prototype.addThumbnail=function(t){var e=this,a=this;return new Promise((function(t,r){/^data:/i.test(e.getURL())?i.resize(e.getURL(),e.data.type,100,100).then((function(e){var r=e[1];a.data.thumbnail=r,t()})).catch(r):i.getDataURI(e.getURL(),{width:100,height:100}).then((function(e){a.data.thumbnail=e[0],t()})).catch(r)}))},Object.defineProperty(i.prototype,"isUploaded",{get:function(){if(!this.parent)throw new Error("No media parent to return disabled status.");return this.parent.isUploaded},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"isDisabled",{get:function(){return this.isUploaded},enumerable:!1,configurable:!0}),i}(i.default);exports.default=u;
@@ -1,5 +1,6 @@
1
1
  import { IObservableArray } from 'mobx';
2
- import Model, { Attrs as AttrsOriginal, Options as OptionsOriginal } from '../Model';
2
+ import Model, { Data as DataOriginal, Options as OptionsOriginal } from '../Model';
3
+ import ElasticOccurrence from './ElasticOccurrence';
3
4
  import Media from './Media';
4
5
  import Sample from './Sample';
5
6
  import { RemoteConfig, Keys } from './helpers';
@@ -9,8 +10,9 @@ export interface Metadata {
9
10
  export interface Options<T = any, S = any> extends OptionsOriginal<T> {
10
11
  metadata?: S;
11
12
  media?: any[];
13
+ Media?: typeof Media<any, any>;
12
14
  }
13
- export interface Attrs extends AttrsOriginal {
15
+ export interface Data extends DataOriginal {
14
16
  training?: boolean;
15
17
  /**
16
18
  * R - released record (default).
@@ -50,8 +52,27 @@ export interface Attrs extends AttrsOriginal {
50
52
  comment?: string;
51
53
  taxon?: any;
52
54
  }
53
- export default class Occurrence<T extends Attrs = Attrs, S extends Metadata = Metadata> extends Model {
54
- static fromJSON(json: any, MediaClass?: any): Occurrence<Attrs, Metadata>;
55
+ export default class Occurrence<T extends Data = Data, S extends Metadata = Metadata> extends Model {
56
+ /**
57
+ * Transform ES document into local structure.
58
+ */
59
+ static parseRemoteJSON({ id, metadata, event, occurrence, taxon }: ElasticOccurrence, remoteUrl: string, survey: any): {
60
+ id: string;
61
+ cid: string;
62
+ createdAt: number;
63
+ updatedAt: number;
64
+ syncedAt: number;
65
+ data: any;
66
+ media: {
67
+ id: string;
68
+ createdAt: number;
69
+ updatedAt: number;
70
+ syncedAt: number;
71
+ data: {
72
+ data: string;
73
+ };
74
+ }[] | undefined;
75
+ };
55
76
  /**
56
77
  * Warehouse attributes and their values.
57
78
  */
@@ -76,12 +97,13 @@ export default class Occurrence<T extends Attrs = Attrs, S extends Metadata = Me
76
97
  values: (val?: boolean | "t" | "f" | null) => "t" | "f";
77
98
  };
78
99
  };
100
+ Media: typeof Media<any, any>;
79
101
  metadata: S;
80
- attrs: T;
102
+ data: T;
81
103
  parent?: Sample;
82
104
  media: IObservableArray<Media>;
83
105
  debouncedValue: number;
84
- constructor({ metadata, media, ...options }?: Options);
106
+ constructor({ metadata, media, Media: MediaClass, ...options }?: Options);
85
107
  setUpdatedAtTimestamp(newUpdatedAt: number): void;
86
108
  /**
87
109
  * Save the model to the offline store.
@@ -105,8 +127,8 @@ export default class Occurrence<T extends Attrs = Attrs, S extends Metadata = Me
105
127
  };
106
128
  modifySubmission?: (submission: any, model: any) => any;
107
129
  };
108
- isUploaded(): boolean;
109
- isDisabled(): boolean;
130
+ get isUploaded(): boolean;
131
+ get isDisabled(): boolean;
110
132
  /**
111
133
  * Returns an object with attributes and their values
112
134
  * mapped for warehouse submission.