Commit b4d90a7b authored by FORESTIER Fabien's avatar FORESTIER Fabien
Browse files

Update resource model and component in order to match with the new version of the service

parent 0373505e
Pipeline #1655 passed with stages
in 11 minutes and 37 seconds
{
"name": "webapp",
"version": "2.1.3",
"version": "2.1.4",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
......@@ -84,4 +84,4 @@
"typescript": "3.2.4",
"webpack-bundle-analyzer": "^3.1.0"
}
}
\ No newline at end of file
}
......@@ -38,22 +38,10 @@ export class DatasetResourcesComponent implements OnInit, OnDestroy {
this.otherResources = [];
this.initialize();
forkJoin([
this._resourcesService.getResources(),
this._resourcesService.getResourceFormats(),
]).subscribe(
this._resourcesService.getResources().subscribe(
(results) => {
const resources = results[0];
const resourceWithFormats = results[1];
this.resources = results;
// We construct the resources object to display inside the template.
this.resources = resources.map((resource) => {
const index = resourceWithFormats.findIndex(e => e.id === resource.id);
if (index !== -1) {
resource.formats = resourceWithFormats[index].formats;
}
return resource;
});
this.initialize();
this.sub = this._datasetDetailService.dataset$.subscribe(() => {
this.initialize();
......
......@@ -13,10 +13,12 @@ export class Format implements IFormat {
isCuttable: number;
isProjectable: number;
constructor(format?: IFormat) {
this.id = format.id;
this.name = format.name;
this.mapServerType = format.mapServerType;
constructor(resourceFormat?: IResourceFormat) {
this.id = resourceFormat.format.id;
this.name = resourceFormat.format.name;
this.mapServerType = resourceFormat.format.mapServerType;
this.isCuttable = resourceFormat.isCuttable;
this.isProjectable = resourceFormat.isProjectable;
}
}
......@@ -31,9 +33,10 @@ export interface IResource {
isStandard: number;
parametersUrl: string;
messageWarning: string;
resourceFormats: IResourceFormat[];
}
export class Resource implements IResource {
export class Resource {
id: number;
name: string;
acronym: string;
......@@ -47,7 +50,7 @@ export class Resource implements IResource {
metadataLink: IMetadataLink;
formats: Format[];
constructor(resource? : IResource) {
constructor(resource?: IResource) {
this.id = resource.id;
this.name = resource.name;
this.acronym = resource.acronym;
......@@ -58,12 +61,19 @@ export class Resource implements IResource {
this.isStandard = resource.isStandard;
this.parametersUrl = resource.parametersUrl;
this.messageWarning = resource.messageWarning;
this.formats = [];
if (resource.resourceFormats) {
this.formats = resource.resourceFormats.map((resourceFormat) => {
return new Format(resourceFormat);
});
} else {
this.formats = [];
}
}
}
export interface IResourceFormat {
resource: IResource;
id: string;
resourceId: string;
format: IFormat;
isProjectable: number;
isCuttable: number;
......
......@@ -18,23 +18,4 @@ export class ResourcesService {
return resourcesBack.map(r => new Resource(r));
}));
}
getResourceFormats() {
return this._httpClient.get<IResourceFormat[]>(`${APP_CONFIG.backendUrls.resources}/resourceformats`).pipe(
map((resourcesBack) => {
const resources = [];
resourcesBack.forEach((result) => {
const format = new Format(result.format);
format.isCuttable = result.isCuttable;
format.isProjectable = result.isProjectable;
let resource = resources.find(r => r.id === result.resource.id);
if (! resource) {
resource = new Resource(result.resource);
resources.push(resource);
}
resource.formats.push(format);
});
return resources;
}));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment