Admin basket: update/fix file import
remove useless AdminBasketFile model definition cleanups, typings
This commit is contained in:
parent
f442272898
commit
b6496f9dba
7 changed files with 109 additions and 178 deletions
|
@ -1,9 +1,7 @@
|
|||
import { Component, OnInit, Input,
|
||||
import { Component, Input,
|
||||
ChangeDetectorRef, ChangeDetectionStrategy } from '@angular/core'
|
||||
import { ActivatedRoute } from '@angular/router'
|
||||
|
||||
import { AdminDataService } from '../../admin-data.service'
|
||||
import { AdminBasketFile } from '../data.service'
|
||||
import { FileImport } from '../../../openapi'
|
||||
|
||||
@Component({
|
||||
selector: 'gisaf-admin-basket-item',
|
||||
|
@ -11,15 +9,10 @@ import { AdminBasketFile } from '../data.service'
|
|||
styleUrls: ['./basket-item.component.css'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class AdminBasketItemComponent implements OnInit {
|
||||
export class AdminBasketItemComponent {
|
||||
constructor(
|
||||
public adminDataService: AdminDataService,
|
||||
private route: ActivatedRoute,
|
||||
private cdr: ChangeDetectorRef,
|
||||
) {}
|
||||
|
||||
@Input() file: AdminBasketFile
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
@Input() file: FileImport
|
||||
}
|
|
@ -1,13 +1,11 @@
|
|||
import { Component, OnInit, Input, ViewChild, ElementRef,
|
||||
ChangeDetectorRef, ChangeDetectionStrategy, SimpleChanges, OnChanges } from '@angular/core'
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { FormGroup, Validators, FormControl } from '@angular/forms'
|
||||
|
||||
import { MatTableDataSource } from '@angular/material/table'
|
||||
|
||||
import { AdminDataService } from '../../admin-data.service'
|
||||
import { AdminBasketFile } from '../data.service'
|
||||
import { AdminBasket, AdminService } from '../../../openapi'
|
||||
import { AdminBasket, AdminService, FileImport } from '../../../openapi'
|
||||
import { MatSnackBar } from '@angular/material/snack-bar'
|
||||
import { HtmlSnackbarComponent } from '../../../custom-snackbar/custom-snackbar.component'
|
||||
|
||||
|
@ -21,7 +19,6 @@ export class AdminBasketUploadComponent implements OnInit, OnChanges {
|
|||
constructor(
|
||||
public adminDataService: AdminDataService,
|
||||
private cdr: ChangeDetectorRef,
|
||||
private http: HttpClient,
|
||||
private snackBar: MatSnackBar,
|
||||
public adminService: AdminService,
|
||||
) {}
|
||||
|
@ -81,33 +78,17 @@ export class AdminBasketUploadComponent implements OnInit, OnChanges {
|
|||
}
|
||||
}).subscribe(
|
||||
resp => {
|
||||
let importResult = resp['import_result']
|
||||
const importTime = resp['time'] || (importResult && importResult['time'])
|
||||
const fileImport = new AdminBasketFile(
|
||||
resp['id'],
|
||||
resp['dir'],
|
||||
resp['name'],
|
||||
resp['url'],
|
||||
resp['md5'],
|
||||
importTime && new Date(importTime),
|
||||
resp['comment'],
|
||||
resp['status'],
|
||||
resp['store'],
|
||||
resp['project'],
|
||||
resp['surveyor'],
|
||||
resp['equipment'],
|
||||
)
|
||||
this.dataSource.data.push(fileImport)
|
||||
this.dataSource.data.push(resp.fileImport)
|
||||
this.dataSource.data = this.dataSource.data
|
||||
let msg = 'File ' + fileImport.name + ' added to basket'
|
||||
if (importResult) {
|
||||
if (resp.details) {
|
||||
this.snackBar.openFromComponent(HtmlSnackbarComponent, {
|
||||
data: importResult
|
||||
data: resp.details
|
||||
//duration: 3000
|
||||
})
|
||||
|
||||
}
|
||||
else {
|
||||
let msg = 'File ' + resp.fileImport.name + ' added to basket'
|
||||
this.snackBar.open(msg, 'Close')
|
||||
}
|
||||
this.cdr.markForCheck()
|
||||
|
|
|
@ -10,8 +10,7 @@ import { MatSort } from '@angular/material/sort'
|
|||
import { MatTableDataSource } from '@angular/material/table'
|
||||
|
||||
import { AdminDataService } from '../admin-data.service'
|
||||
import { AdminBasketFile } from './data.service'
|
||||
import { AdminBasket, AdminService } from '../../openapi'
|
||||
import { AdminBasket, AdminService, FileImport } from '../../openapi'
|
||||
import { HtmlSnackbarComponent } from '../../custom-snackbar/custom-snackbar.component'
|
||||
|
||||
@Component({
|
||||
|
@ -73,11 +72,11 @@ export class AdminBasketComponent implements OnInit {
|
|||
this.dataSource.filter = this.filterText.trim().toLowerCase()
|
||||
}
|
||||
|
||||
download(item: AdminBasketFile) {
|
||||
download(item: FileImport) {
|
||||
window.open('/api/admin/basket/download/' + this.basket.name + '/' + item.id + '/' + item.name)
|
||||
}
|
||||
|
||||
importItem(item: AdminBasketFile, dryRun: boolean) {
|
||||
importItem(item: FileImport, dryRun: boolean) {
|
||||
return this.adminService.importBasketFileApiAdminBasketImportBasketFileIdGet({
|
||||
basket: this.basket.name,
|
||||
fileId: item.id,
|
||||
|
@ -94,7 +93,7 @@ export class AdminBasketComponent implements OnInit {
|
|||
)
|
||||
}
|
||||
|
||||
deleteItem(item: AdminBasketFile) {
|
||||
deleteItem(item: FileImport) {
|
||||
return this.adminService.deleteBasketFileApiAdminBasketDeleteBasketFileIdGet({
|
||||
basket: this.basket.name,
|
||||
fileId: item.id
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
import { Injectable } from '@angular/core'
|
||||
|
||||
import { Observable, of as observableOf } from 'rxjs'
|
||||
import { map } from 'rxjs/operators'
|
||||
|
||||
// import { Apollo, gql } from 'apollo-angular'
|
||||
|
||||
import { AdminService, AdminBasket, BasketNameOnly, Project,
|
||||
BasketImportResult
|
||||
} from '../../openapi'
|
||||
|
||||
export class AdminBasketFile {
|
||||
constructor(
|
||||
public id: number,
|
||||
public dir: string,
|
||||
public name: string,
|
||||
public url: string,
|
||||
public md5: string,
|
||||
public time: Date,
|
||||
public comment: string,
|
||||
public status: string,
|
||||
public store: string,
|
||||
public project: string,
|
||||
public surveyor: string,
|
||||
public equipment: string,
|
||||
public import_result?: string,
|
||||
) {}
|
||||
}
|
||||
|
||||
export class AdminBasketUploadFieldData {
|
||||
constructor(
|
||||
public stores: string[],
|
||||
public statuses: string[],
|
||||
public projects: string[],
|
||||
public surveyors: string[],
|
||||
public equipments: string[],
|
||||
) {}
|
||||
}
|
|
@ -196,67 +196,6 @@ export const $AdminBasket = {
|
|||
title: 'AdminBasket'
|
||||
} as const;
|
||||
|
||||
export const $AdminBasketFile = {
|
||||
properties: {
|
||||
id: {
|
||||
type: 'integer',
|
||||
title: 'Id'
|
||||
},
|
||||
dir: {
|
||||
type: 'string',
|
||||
title: 'Dir'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
title: 'Name'
|
||||
},
|
||||
url: {
|
||||
type: 'string',
|
||||
title: 'Url'
|
||||
},
|
||||
md5: {
|
||||
type: 'string',
|
||||
title: 'Md5'
|
||||
},
|
||||
time: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
title: 'Time'
|
||||
},
|
||||
comment: {
|
||||
type: 'string',
|
||||
title: 'Comment'
|
||||
},
|
||||
status: {
|
||||
type: 'string',
|
||||
title: 'Status'
|
||||
},
|
||||
store: {
|
||||
type: 'string',
|
||||
title: 'Store'
|
||||
},
|
||||
project: {
|
||||
type: 'string',
|
||||
title: 'Project'
|
||||
},
|
||||
surveyor: {
|
||||
type: 'string',
|
||||
title: 'Surveyor'
|
||||
},
|
||||
equipment: {
|
||||
type: 'string',
|
||||
title: 'Equipment'
|
||||
},
|
||||
import_result: {
|
||||
type: 'string',
|
||||
title: 'Import Result'
|
||||
}
|
||||
},
|
||||
type: 'object',
|
||||
required: ['id', 'dir', 'name', 'url', 'md5', 'time', 'comment', 'status', 'store', 'project', 'surveyor', 'equipment', 'import_result'],
|
||||
title: 'AdminBasketFile'
|
||||
} as const;
|
||||
|
||||
export const $Attachment = {
|
||||
properties: {
|
||||
name: {
|
||||
|
@ -386,7 +325,14 @@ export const $BasketImportResult = {
|
|||
title: 'Time'
|
||||
},
|
||||
message: {
|
||||
type: 'string',
|
||||
anyOf: [
|
||||
{
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
type: 'null'
|
||||
}
|
||||
],
|
||||
title: 'Message'
|
||||
},
|
||||
details: {
|
||||
|
@ -415,10 +361,19 @@ export const $BasketImportResult = {
|
|||
}
|
||||
],
|
||||
title: 'Details'
|
||||
},
|
||||
fileImport: {
|
||||
anyOf: [
|
||||
{
|
||||
'$ref': '#/components/schemas/FileImport'
|
||||
},
|
||||
{
|
||||
type: 'null'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
type: 'object',
|
||||
required: ['message'],
|
||||
title: 'BasketImportResult'
|
||||
} as const;
|
||||
|
||||
|
@ -1313,7 +1268,14 @@ export const $FileImport = {
|
|||
title: 'Id'
|
||||
},
|
||||
url: {
|
||||
type: 'string',
|
||||
anyOf: [
|
||||
{
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
type: 'null'
|
||||
}
|
||||
],
|
||||
title: 'Url'
|
||||
},
|
||||
dir: {
|
||||
|
@ -1329,20 +1291,48 @@ export const $FileImport = {
|
|||
title: 'Md5'
|
||||
},
|
||||
time: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
anyOf: [
|
||||
{
|
||||
type: 'string',
|
||||
format: 'date-time'
|
||||
},
|
||||
{
|
||||
type: 'null'
|
||||
}
|
||||
],
|
||||
title: 'Time'
|
||||
},
|
||||
comment: {
|
||||
type: 'string',
|
||||
anyOf: [
|
||||
{
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
type: 'null'
|
||||
}
|
||||
],
|
||||
title: 'Comment'
|
||||
},
|
||||
status: {
|
||||
type: 'string',
|
||||
anyOf: [
|
||||
{
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
type: 'null'
|
||||
}
|
||||
],
|
||||
title: 'Status'
|
||||
},
|
||||
store: {
|
||||
type: 'string',
|
||||
anyOf: [
|
||||
{
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
type: 'null'
|
||||
}
|
||||
],
|
||||
title: 'Store'
|
||||
},
|
||||
basket: {
|
||||
|
@ -1350,15 +1340,36 @@ export const $FileImport = {
|
|||
title: 'Basket'
|
||||
},
|
||||
project_id: {
|
||||
type: 'integer',
|
||||
anyOf: [
|
||||
{
|
||||
type: 'integer'
|
||||
},
|
||||
{
|
||||
type: 'null'
|
||||
}
|
||||
],
|
||||
title: 'Project Id'
|
||||
},
|
||||
surveyor_id: {
|
||||
type: 'integer',
|
||||
anyOf: [
|
||||
{
|
||||
type: 'integer'
|
||||
},
|
||||
{
|
||||
type: 'null'
|
||||
}
|
||||
],
|
||||
title: 'Surveyor Id'
|
||||
},
|
||||
equipment_id: {
|
||||
type: 'integer',
|
||||
anyOf: [
|
||||
{
|
||||
type: 'integer'
|
||||
},
|
||||
{
|
||||
type: 'null'
|
||||
}
|
||||
],
|
||||
title: 'Equipment Id'
|
||||
},
|
||||
path: {
|
||||
|
@ -1369,7 +1380,7 @@ export const $FileImport = {
|
|||
}
|
||||
},
|
||||
type: 'object',
|
||||
required: ['url', 'dir', 'name', 'md5', 'time', 'comment', 'status', 'store', 'basket', 'project_id', 'surveyor_id', 'equipment_id', 'path'],
|
||||
required: ['dir', 'name', 'md5', 'basket', 'project_id', 'surveyor_id', 'equipment_id', 'path'],
|
||||
title: 'FileImport',
|
||||
description: `Files to import or imported in the DB.
|
||||
Give either url or path.`
|
||||
|
|
|
@ -433,7 +433,7 @@ export class AdminService {
|
|||
|
||||
/**
|
||||
* Upload Basket File
|
||||
* @returns AdminBasketFile Successful Response
|
||||
* @returns BasketImportResult Successful Response
|
||||
* @throws ApiError
|
||||
*/
|
||||
public uploadBasketFileApiAdminBasketUploadNamePost(data: $OpenApiTs['/api/admin/basket/upload/{name}']['post']['req']): Observable<$OpenApiTs['/api/admin/basket/upload/{name}']['post']['res'][200]> {
|
||||
|
|
|
@ -42,22 +42,6 @@ export type AdminBasket = {
|
|||
projects?: Array<Project>;
|
||||
};
|
||||
|
||||
export type AdminBasketFile = {
|
||||
id: number;
|
||||
dir: string;
|
||||
name: string;
|
||||
url: string;
|
||||
md5: string;
|
||||
time: string;
|
||||
comment: string;
|
||||
status: string;
|
||||
store: string;
|
||||
project: string;
|
||||
surveyor: string;
|
||||
equipment: string;
|
||||
import_result: string;
|
||||
};
|
||||
|
||||
export type Attachment = {
|
||||
name: string;
|
||||
path: string;
|
||||
|
@ -89,10 +73,11 @@ export type BasketDefault = {
|
|||
|
||||
export type BasketImportResult = {
|
||||
time?: string;
|
||||
message: string;
|
||||
message?: string | null;
|
||||
details?: {
|
||||
[key: string]: (string | number | boolean);
|
||||
} | null;
|
||||
fileImport?: FileImport | null;
|
||||
};
|
||||
|
||||
export type BasketNameOnly = {
|
||||
|
@ -263,18 +248,18 @@ export type FeatureInfo = {
|
|||
*/
|
||||
export type FileImport = {
|
||||
id?: number | null;
|
||||
url: string;
|
||||
url?: string | null;
|
||||
dir: string;
|
||||
name: string;
|
||||
md5: string;
|
||||
time: string;
|
||||
comment: string;
|
||||
status: string;
|
||||
store: string;
|
||||
time?: string | null;
|
||||
comment?: string | null;
|
||||
status?: string | null;
|
||||
store?: string | null;
|
||||
basket: string;
|
||||
project_id: number;
|
||||
surveyor_id: number;
|
||||
equipment_id: number;
|
||||
project_id: number | null;
|
||||
surveyor_id: number | null;
|
||||
equipment_id: number | null;
|
||||
readonly path: string;
|
||||
};
|
||||
|
||||
|
@ -848,7 +833,7 @@ export type $OpenApiTs = {
|
|||
/**
|
||||
* Successful Response
|
||||
*/
|
||||
200: AdminBasketFile;
|
||||
200: BasketImportResult;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue