diff --git a/src/app/models/ui-request.model.ts b/src/app/models/ui-request.model.ts index 7b022c23..f3c10560 100644 --- a/src/app/models/ui-request.model.ts +++ b/src/app/models/ui-request.model.ts @@ -271,6 +271,24 @@ export class EditTableRequest { } } +/** + * Transfer a table from one namespace to another. + * Used for request where you want to transfer a table + */ + export class TransferTableRequest { + table: string; + sourceSchema: string; + targetSchema: string; + primaryKeyNames: string; + + constructor( table: string, sourceNamespaceName: string, targetNamespaceName: string, primaryKeyNames: string ) { + this.table = table; + this.sourceSchema = sourceNamespaceName; + this.targetSchema = targetNamespaceName; + this.primaryKeyNames = primaryKeyNames; + } +} + export class EditCollectionRequest { database: string; collection: string; diff --git a/src/app/services/crud.service.ts b/src/app/services/crud.service.ts index b9933953..f4a12b8c 100644 --- a/src/app/services/crud.service.ts +++ b/src/app/services/crud.service.ts @@ -19,6 +19,7 @@ import { GraphRequest, MaterializedRequest, MonitoringRequest, + TransferTableRequest, QueryRequest, RelAlgRequest, Schema, @@ -225,6 +226,13 @@ export class CrudService { return this._http.post(`${this.httpUrl}/createTable`, tableRequest, this.httpOptions); } + /** + * Transfer a table to another schema + */ + transferTable( tableRequest: TransferTableRequest ) { + return this._http.post(`${this.httpUrl}/transferTable`, tableRequest, this.httpOptions); + } + /** * Create a new collection */ diff --git a/src/app/views/schema-editing/document-edit-collections/document-edit-collections.component.html b/src/app/views/schema-editing/document-edit-collections/document-edit-collections.component.html index c2c7c175..903948f3 100644 --- a/src/app/views/schema-editing/document-edit-collections/document-edit-collections.component.html +++ b/src/app/views/schema-editing/document-edit-collections/document-edit-collections.component.html @@ -11,6 +11,7 @@
Collections in {{database}} [{{schemaType}}]
Collection Truncate Drop + Transfer @@ -50,6 +51,26 @@
Collections in {{database}} [{{schemaType}}]
+ +
+
+
+ + +
+ +
+
+ @@ -189,3 +210,37 @@ + + diff --git a/src/app/views/schema-editing/document-edit-collections/document-edit-collections.component.ts b/src/app/views/schema-editing/document-edit-collections/document-edit-collections.component.ts index aa15c042..499f5827 100644 --- a/src/app/views/schema-editing/document-edit-collections/document-edit-collections.component.ts +++ b/src/app/views/schema-editing/document-edit-collections/document-edit-collections.component.ts @@ -1,6 +1,6 @@ import {Component, OnDestroy, OnInit, ViewChild} from '@angular/core'; import {CrudService} from '../../../services/crud.service'; -import {EditCollectionRequest, EditTableRequest, SchemaRequest} from '../../../models/ui-request.model'; +import {EditCollectionRequest, EditTableRequest, SchemaRequest, TransferTableRequest} from '../../../models/ui-request.model'; import {ActivatedRoute, Router} from '@angular/router'; import {DbColumn, Index, PolyType, ResultSet, Status} from '../../../components/data-view/models/result-set.model'; import {ToastDuration, ToastService} from '../../../components/toast/toast.service'; @@ -15,13 +15,18 @@ import {UtilService} from '../../../services/util.service'; import * as $ from 'jquery'; import {DbTable} from '../../uml/uml.model'; +class Namespace { + name: string; + id: string; +} + @Component({ selector: 'app-document-edit-collections', templateUrl: './document-edit-collections.component.html', styleUrls: ['./document-edit-collections.component.scss'] }) export class DocumentEditCollectionsComponent implements OnInit, OnDestroy { - + types: PolyType[] = []; database: string; schemaType: string; @@ -34,6 +39,11 @@ export class DocumentEditCollectionsComponent implements OnInit, OnDestroy { selectedStore; creatingTable = false; + activeNamespace: string; + namespaces: Namespace[]; + selectedSchemas = new Map(); // name of the collection, name of the selected namespace + tableToTransfer : TableModel; + //export table showExportButton = false; exportProgress = 0.0; @@ -47,6 +57,11 @@ export class DocumentEditCollectionsComponent implements OnInit, OnDestroy { addDefaultValue: new FormControl(true, Validators.required) }); @ViewChild('exportTableModal', {static: false}) public exportTableModal: ModalDirective; + transferTableForm = new FormGroup({ + name: new FormControl('', Validators.required), + }); + @ViewChild('transferTableModal', {static: false}) public transferTableModal: ModalDirective; + constructor( public _crud: CrudService, @@ -78,6 +93,7 @@ export class DocumentEditCollectionsComponent implements OnInit, OnDestroy { }); this.subscriptions.add(sub2); this.documentListener(); + this.updateExistingSchemas(); } ngOnDestroy() { @@ -380,6 +396,72 @@ export class DocumentEditCollectionsComponent implements OnInit, OnDestroy { ); } + /** + * Transfer table (a collection) from one namepsace to another + */ + transferTable() { + let primaryKeyNames = this.transferTableForm.controls['name'].value; + const req = new TransferTableRequest( this.tableToTransfer.name, this.database, this.getSelectedSchemaForTable(this.tableToTransfer), primaryKeyNames); + this._crud.transferTable( req ).subscribe( + res => { + const result = res; + if (result.error) { + this._toast.exception(result, 'Could not transfer collection:'); + } else { + this._toast.success('Transfered collection ' + this.tableToTransfer.name, result.generatedQuery); + this.updateExistingSchemas(); + this.selectedSchemas.delete(this.tableToTransfer.name); + this._leftSidebar.setSchema(new SchemaRequest('/views/schema-editing/', true, 2, false), this._router); + } + this.getTables(); + }, err => { + this._toast.error('Could not transfer collection'); + console.log(err); + } + ).add(() => { + this.transferTableModal.hide(); + }); + } + + selectSchemaForTable(table : TableModel, selectedSchema : string) { + this.selectedSchemas.set(table.name, selectedSchema); + } + + getSelectedSchemaForTable(table : TableModel) { + return this.selectedSchemas.get(table.name); + } + + getAvailableSchemas (): Namespace[] { + if(!this.namespaces) { return []; } + return this.namespaces.filter( (n: Namespace) => { + return n.name != this.database; + }); + } + + private updateExistingSchemas() { + this._crud.getSchema(new SchemaRequest('views/querying/console/', false, 1, false)).subscribe( + res => { + this.namespaces = []; + for (const namespace of res) { + this.namespaces.push(namespace); + } + } + ); + } + + initTransferTableModal(table : TableModel ){ + let selectedSchema = this.getSelectedSchemaForTable(table) + if (selectedSchema == undefined) { + return; + } + this.tableToTransfer = table; + this.transferTableModal.show(); + } + + clearTransferTableModal(){ + this.selectedStore = null; + } + } class TableModel { diff --git a/src/app/views/schema-editing/edit-tables/edit-tables.component.html b/src/app/views/schema-editing/edit-tables/edit-tables.component.html index 2b23b471..fc24e8b6 100644 --- a/src/app/views/schema-editing/edit-tables/edit-tables.component.html +++ b/src/app/views/schema-editing/edit-tables/edit-tables.component.html @@ -11,6 +11,7 @@
Tables in {{schema}} [{{schemaType}}]
Table Truncate Drop + Transfer @@ -50,6 +51,26 @@
Tables in {{schema}} [{{schemaType}}]
+ +
+
+
+ + +
+ +
+
+ diff --git a/src/app/views/schema-editing/edit-tables/edit-tables.component.ts b/src/app/views/schema-editing/edit-tables/edit-tables.component.ts index 39cc57c4..ecfc43db 100644 --- a/src/app/views/schema-editing/edit-tables/edit-tables.component.ts +++ b/src/app/views/schema-editing/edit-tables/edit-tables.component.ts @@ -1,6 +1,6 @@ import {Component, OnDestroy, OnInit, ViewChild} from '@angular/core'; import {CrudService} from '../../../services/crud.service'; -import {EditTableRequest, SchemaRequest} from '../../../models/ui-request.model'; +import {EditTableRequest, SchemaRequest, TransferTableRequest} from '../../../models/ui-request.model'; import {ActivatedRoute, Router} from '@angular/router'; import {DbColumn, Index, PolyType, ResultSet, Status} from '../../../components/data-view/models/result-set.model'; import {ToastDuration, ToastService} from '../../../components/toast/toast.service'; @@ -15,6 +15,11 @@ import {UtilService} from '../../../services/util.service'; import * as $ from 'jquery'; import {DbTable} from '../../uml/uml.model'; +class Namespace { + name: string; + id: string; +} + @Component({ selector: 'app-edit-tables', templateUrl: './edit-tables.component.html', @@ -22,6 +27,8 @@ import {DbTable} from '../../uml/uml.model'; }) export class EditTablesComponent implements OnInit, OnDestroy { + private readonly LOCAL_STORAGE_NAMESPACE_KEY = 'polypheny-namespace'; + types: PolyType[] = []; schema: string; schemaType: string; @@ -34,6 +41,10 @@ export class EditTablesComponent implements OnInit, OnDestroy { selectedStore; creatingTable = false; + activeNamespace: string; + namespaces: Namespace[]; + selectedSchemas = new Map(); // name of the table, name of the selected namespace + //export table showExportButton = false; exportProgress = 0.0; @@ -79,6 +90,7 @@ export class EditTablesComponent implements OnInit, OnDestroy { }); this.subscriptions.add(sub2); this.documentListener(); + this.updateExistingSchemas(); } ngOnDestroy() { @@ -105,6 +117,25 @@ export class EditTablesComponent implements OnInit, OnDestroy { }); } + getAvailableSchemas (): Namespace[] { + if(!this.namespaces) { return []; } + return this.namespaces.filter( (n: Namespace) => { + return n.name != this.schema; + }); + } + + private updateExistingSchemas() { + this._crud.getSchema(new SchemaRequest('views/querying/console/', false, 1, false)).subscribe( + res => { + this.namespaces = []; + for (const namespace of res) { + this.namespaces.push(namespace); + } + } + ); + } + + getTables() { this._crud.getTables(new EditTableRequest(this.schema)).subscribe( res => { @@ -368,6 +399,35 @@ export class EditTablesComponent implements OnInit, OnDestroy { } } + transferTable(table : TableModel) { + const req = new TransferTableRequest( table.name, this.schema, this.getSelectedSchemaForTable(table), null) + this._crud.transferTable( req ).subscribe( + res => { + const result = res; + if (result.error) { + this._toast.exception(result, 'Could not transfer table:'); + } else { + this._toast.success('Transfered table ' + table.name, result.generatedQuery); + this.updateExistingSchemas(); + this.selectedSchemas.delete(table.name); + this._leftSidebar.setSchema(new SchemaRequest('/views/schema-editing/', true, 2, false), this._router); + } + this.getTables(); + }, err => { + this._toast.error('Could not transfer table'); + console.log(err); + } + ); + } + + selectSchemaForTable(table : TableModel, selectedSchema : string) { + this.selectedSchemas.set(table.name, selectedSchema); + } + + getSelectedSchemaForTable(table : TableModel) { + return this.selectedSchemas.get(table.name); + } + initSocket() { const sub = this._crud.onSocketEvent().subscribe( msg => {