Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/move table #2

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/app/models/ui-request.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/app/services/crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
GraphRequest,
MaterializedRequest,
MonitoringRequest,
TransferTableRequest,
QueryRequest,
RelAlgRequest,
Schema,
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h5>Collections in <i>{{database}}</i> [{{schemaType}}]</h5>
<th>Collection</th>
<th>Truncate</th>
<th>Drop</th>
<th *ngIf="getAvailableSchemas().length > 0">Transfer</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -50,6 +51,26 @@ <h5>Collections in <i>{{database}}</i> [{{schemaType}}]</h5>
</div>
</div>
</td>
<td *ngIf="getAvailableSchemas().length > 0">
<div class="input-group confirm-group" *ngIf="table.modifiable">
<div class="btn-group btn-group-sm" id="transferBtnGroup">
<div class="btn-group btn-group-sm" dropdown placement="top right">
<button dropdownToggle type="button" class="btn btn-primary dropdown-toggle" style="min-width:140px">
<span *ngIf="!getSelectedSchemaForTable(table)">Select namespace</span>
<span *ngIf="getSelectedSchemaForTable(table)">{{getSelectedSchemaForTable(table)}}</span>
<span class="canewret"></span>
</button>
<ul *dropdownMenu class="dropdown-menu dropdown-menu-right" role="menu">
<ng-container *ngFor="let namespace of getAvailableSchemas()">
<li role="menuitem"><a class="dropdown-item" [routerLink]="[]" (click)="selectSchemaForTable(table, namespace.name)">{{namespace.name}}</a></li>
</ng-container>
<li *ngIf="getAvailableSchemas().length === 0" role="menuitem"><a class="dropdown-item disabled" [routerLink]="[]">no other namespaces available</a></li>
</ul>
</div>
<button class="btn btn-primary btn-sm" (click)="initTransferTableModal(table)">transfer</button>
</div>
</div>
</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -189,3 +210,37 @@ <h4 class="modal-title">Export tables</h4>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>

<div bsModal #transferTableModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form [formGroup]="transferTableForm">
<div class="modal-header">
<h4 class="modal-title">Transfer collection to relational namespace</h4>
<button type="button" class="close" (click)="transferTableModal.hide()" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>

<div class="modal-body">
<p>The transfer of a document-based collection to a relational namespace only works to a limited extent. Please select a field that should become the primary key.
Example for the input: ("id1","id2")
</p>
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend"><label for="fieldName" class="input-group-text">Field</label></div>
<input type="text" placeholder="name" id="fieldName" class="form-control" formControlName="name"
autocomplete="off">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" (click)="transferTableModal.hide()">Close</button>
<button type="button" class="btn btn-primary" (click)="transferTable()" [disabled]="uploading">
Transfer
</button>
</div>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand All @@ -34,6 +39,11 @@ export class DocumentEditCollectionsComponent implements OnInit, OnDestroy {
selectedStore;
creatingTable = false;

activeNamespace: string;
namespaces: Namespace[];
selectedSchemas = new Map<string, string>(); // name of the collection, name of the selected namespace
tableToTransfer : TableModel;

//export table
showExportButton = false;
exportProgress = 0.0;
Expand All @@ -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,
Expand Down Expand Up @@ -78,6 +93,7 @@ export class DocumentEditCollectionsComponent implements OnInit, OnDestroy {
});
this.subscriptions.add(sub2);
this.documentListener();
this.updateExistingSchemas();
}

ngOnDestroy() {
Expand Down Expand Up @@ -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 = <ResultSet>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 <Namespace[]>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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h5>Tables in <i>{{schema}}</i> [{{schemaType}}]</h5>
<th>Table</th>
<th>Truncate</th>
<th>Drop</th>
<th *ngIf="getAvailableSchemas().length > 0">Transfer</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -50,6 +51,26 @@ <h5>Tables in <i>{{schema}}</i> [{{schemaType}}]</h5>
</div>
</div>
</td>
<td *ngIf="getAvailableSchemas().length > 0">
<div class="input-group confirm-group" *ngIf="table.modifiable">
<div class="btn-group btn-group-sm" id="moveBtnGroup">
<div class="btn-group btn-group-sm" dropdown placement="top right">
<button dropdownToggle type="button" class="btn btn-primary dropdown-toggle" style="min-width:140px">
<span *ngIf="!getSelectedSchemaForTable(table)">Select namespace</span>
<span *ngIf="getSelectedSchemaForTable(table)">{{getSelectedSchemaForTable(table)}}</span>
<span class="canewret"></span>
</button>
<ul *dropdownMenu class="dropdown-menu dropdown-menu-right" role="menu">
<ng-container *ngFor="let namespace of getAvailableSchemas()">
<li role="menuitem"><a class="dropdown-item" [routerLink]="[]" (click)="selectSchemaForTable(table, namespace.name)">{{namespace.name}}</a></li>
</ng-container>
<li *ngIf="getAvailableSchemas().length === 0" role="menuitem"><a class="dropdown-item disabled" [routerLink]="[]">no other namespaces available</a></li>
</ul>
</div>
<button class="btn btn-primary btn-sm" (click)="transferTable(table)">transfer</button>
</div>
</div>
</td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -15,13 +15,20 @@ 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',
styleUrls: ['./edit-tables.component.scss']
})
export class EditTablesComponent implements OnInit, OnDestroy {

private readonly LOCAL_STORAGE_NAMESPACE_KEY = 'polypheny-namespace';

types: PolyType[] = [];
schema: string;
schemaType: string;
Expand All @@ -34,6 +41,10 @@ export class EditTablesComponent implements OnInit, OnDestroy {
selectedStore;
creatingTable = false;

activeNamespace: string;
namespaces: Namespace[];
selectedSchemas = new Map<string, string>(); // name of the table, name of the selected namespace

//export table
showExportButton = false;
exportProgress = 0.0;
Expand Down Expand Up @@ -79,6 +90,7 @@ export class EditTablesComponent implements OnInit, OnDestroy {
});
this.subscriptions.add(sub2);
this.documentListener();
this.updateExistingSchemas();
}

ngOnDestroy() {
Expand All @@ -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 <Namespace[]>res) {
this.namespaces.push(namespace);
}
}
);
}


getTables() {
this._crud.getTables(new EditTableRequest(this.schema)).subscribe(
res => {
Expand Down Expand Up @@ -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 = <ResultSet>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 => {
Expand Down