2018-02-21 09:46:04 -08:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { get, setProperties } from '@ember/object';
|
|
|
|
import { task } from 'ember-concurrency';
|
|
|
|
import { IDatasetColumn, IDatasetColumnWithHtmlComments } from 'wherehows-web/typings/api/datasets/columns';
|
|
|
|
import { IDatasetSchema } from 'wherehows-web/typings/api/datasets/schema';
|
|
|
|
import { augmentObjectsWithHtmlComments } from 'wherehows-web/utils/api/datasets/columns';
|
|
|
|
import { readDatasetSchemaByUrn } from 'wherehows-web/utils/api/datasets/schema';
|
|
|
|
|
|
|
|
export default class DatasetSchemaContainer extends Component {
|
|
|
|
/**
|
|
|
|
* The urn identifier for the dataset
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
urn: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* json string for the dataset schema properties
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
json: string;
|
|
|
|
|
2018-03-29 15:27:24 -07:00
|
|
|
/**
|
|
|
|
* Stores the last modified date on the dataset schema as an utc time string
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-04-02 14:24:49 -07:00
|
|
|
lastModifiedString: string;
|
2018-03-29 15:27:24 -07:00
|
|
|
|
2018-02-21 09:46:04 -08:00
|
|
|
/**
|
|
|
|
* List of schema properties for the dataset
|
|
|
|
* @type {IDatasetColumnWithHtmlComments | IDatasetColumn}
|
|
|
|
*/
|
|
|
|
schemas: Array<IDatasetColumnWithHtmlComments | IDatasetColumn>;
|
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
get(this, 'getDatasetSchemaTask').perform();
|
|
|
|
}
|
|
|
|
|
|
|
|
didUpdateAttrs() {
|
|
|
|
get(this, 'getDatasetSchemaTask').perform();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the schema for the dataset
|
|
|
|
* @type {Task<Promise<IDatasetSchema>, (a?: any) => TaskInstance<Promise<IDatasetSchema>>>}
|
|
|
|
*/
|
|
|
|
getDatasetSchemaTask = task(function*(this: DatasetSchemaContainer): IterableIterator<Promise<IDatasetSchema>> {
|
|
|
|
let schemas,
|
2018-03-29 15:27:24 -07:00
|
|
|
{ columns, rawSchema: json, lastModified }: IDatasetSchema = yield readDatasetSchemaByUrn(get(this, 'urn'));
|
|
|
|
|
|
|
|
let lastModifiedString = new Date(lastModified).toLocaleString();
|
|
|
|
|
2018-02-21 09:46:04 -08:00
|
|
|
schemas = augmentObjectsWithHtmlComments(columns);
|
|
|
|
json || (json = '{}');
|
|
|
|
|
2018-04-02 14:24:49 -07:00
|
|
|
setProperties(this, { schemas, json, lastModifiedString });
|
2018-02-21 09:46:04 -08:00
|
|
|
});
|
|
|
|
}
|