Skip to content

Commit

Permalink
Implemented #431 and #21
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Jan 13, 2017
1 parent 7aa86dc commit 1406527
Show file tree
Hide file tree
Showing 29 changed files with 1,269 additions and 18 deletions.
10 changes: 9 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import 'font-awesome/css/font-awesome.css';

import 'spectrum-colorpicker/spectrum.css';
import 'ui-select/dist/select.min.css';

import 'ng-tags-input/build/ng-tags-input.min.css';
import 'ng-tags-input/build/ng-tags-input.bootstrap.min.css';
import 'c3/c3.min.css';
Expand Down Expand Up @@ -87,6 +88,11 @@ import ConfigurationController from './controllers/configuration-controller'
import EEController from './controllers/ee-controller'
import SchemaController from './controllers/schema-controller'


// COMPONENTS Angular 1.5

import APP_COMPONENTS_LEGACY from './components';

// WIDGET

import CodeMirrorUI from './directives/ui-codemirror';
Expand Down Expand Up @@ -126,6 +132,7 @@ let deps = [HeaderController,
ConfigurationController,
EEController,
SchemaController,
...APP_COMPONENTS_LEGACY,
'mgcrea.ngStrap',
CodeMirrorUI,
'LocalStorageModule',
Expand All @@ -135,7 +142,8 @@ let deps = [HeaderController,
'history.services',
'browse.services',
'ee.services',
'graph.services',
'schema.services',
'legacy.filters',
BootstrapTabSet,
'ngTable',
'filters',
Expand Down
1 change: 0 additions & 1 deletion src/app/app.declarations.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {ImportExport} from './dbconfiguration';



export const APP_DECLARATIONS = [
ImportExport
];
15 changes: 12 additions & 3 deletions src/app/app.resolver.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import {DBService, GraphService} from './core/services';
import {DBService, GraphService, SchemaService, CommandService} from './core/services';
import {FormatArrayPipe, FormatErrorPipe} from './core/pipes';

const APP_PIPES = [
FormatArrayPipe,
FormatErrorPipe
]

const APP_SERVICES = [
DBService,
GraphService
GraphService,
SchemaService,
CommandService
]


export const APP_RESOLVER_PROVIDERS = [
...APP_SERVICES
...APP_SERVICES,
...APP_PIPES
];
22 changes: 22 additions & 0 deletions src/app/core/pipes/formatArray.pipe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {downgradeInjectable} from '@angular/upgrade/static';

class FormatArrayPipe {

transform(input) {
if (input instanceof Array) {
var output = "";
input.forEach(function (e, idx) {
output += (idx > 0 ? ", " : " ") + e;
})
return output;
} else {
return input;
}
}
}

angular.module('legacy.filters', []).factory(
`FormatArrayPipe`,
downgradeInjectable(FormatArrayPipe));

export {FormatArrayPipe};
20 changes: 20 additions & 0 deletions src/app/core/pipes/formatError.pipe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {downgradeInjectable} from '@angular/upgrade/static';

class FormatErrorPipe {

transform(input) {
if (typeof input == 'string') {
return input;
} else if (typeof input == 'object') {
return input.errors[0].content;
} else {
return input;
}
}
}

angular.module('legacy.filters', []).factory(
`FormatErrorPipe`,
downgradeInjectable(FormatErrorPipe));

export {FormatErrorPipe};
2 changes: 2 additions & 0 deletions src/app/core/pipes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './formatArray.pipe';
export * from './formatError.pipe';
29 changes: 29 additions & 0 deletions src/app/core/services/command.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {downgradeInjectable} from '@angular/upgrade/static';
import {Http} from '@angular/http';
import 'rxjs/add/operator/toPromise';

import {API} from '../../../constants';

class CommandService {
constructor(http) {
this.http = http;
}


command({db, language, query, limit}) {
let startTime = new Date().getTime();
limit = limit || 20;
language = language || 'sql';
let url = API + 'command/' + db + "/" + language + "/-/" + limit + '?format=rid,type,version,class,graph';
query = query.trim();
return this.http.post(url, query).toPromise();
}
}

CommandService.parameters = [[Http]];

angular.module('command.services', []).factory(
`CommandService`,
downgradeInjectable(CommandService));

export {CommandService};
1 change: 1 addition & 0 deletions src/app/core/services/database.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {API} from '../../../constants';



class DBService {
exportDB(db) {
window.open(API + 'export/' + db);
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/services/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './graph.service';
export * from './database.service';
export * from './schema.service';
export * from './command.service';
144 changes: 144 additions & 0 deletions src/app/core/services/schema.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import {downgradeInjectable} from '@angular/upgrade/static';
import {CommandService} from './command.service';
import {FormatArrayPipe} from '../pipes';

class SchemaService {
constructor(commandService, arrayPipe) {
this.commandService = commandService;
this.arrayPipe = arrayPipe;

this.systems = ["OUser",
"ORole",
"OIdentity",
"_studio",
"OFunction",
"ORestricted",
"OShape",
"OPoint",
"OGeometryCollection",
"OLineString",
"OMultiLineString",
"OMultiPoint",
"OPolygon",
"OMultiPolygon",
"ORectangle",
"OSchedule",
"OSequence",
"OTriggered"];
}

createClass(db, {name, abstract, superClasses, clusters}) {

let query = 'CREATE CLASS `' + name + "`";
let abstractSQL = abstract ? ' ABSTRACT ' : '';
let superClassesSQL = '';
if ((superClasses != null && superClasses.length > 0)) {
superClassesSQL = ' extends ' + this.arrayPipe.transform((superClasses.map((c) => {
return "`" + c + "`"
})));
}
let clusterSQL = '';
if (clusters) {
clusterSQL = `CLUSTERS ${clusters}`;
}

query = query + superClassesSQL + clusterSQL + abstractSQL;
return this.commandService.command({
db,
query
})
}

alterClass(db, {clazz, name, value}) {
let query = `ALTER CLASS \`${clazz}\` ${name} ${value} `;
return this.commandService.command({
db,
query
})
}


createProperty(db, {clazz, name, type, linkedType, linkedClass}) {

linkedType = linkedType || '';
linkedClass = linkedClass || '';
let query = `CREATE PROPERTY \`${clazz}\`.\`${name}\` ${type} ${linkedType} ${linkedClass}`;
return this.commandService.command({
db,
query
})
}

isSystemClass(c) {
return this.systems.indexOf(c) != -1;
}

genericClasses(classes) {
return classes.filter((c) => {
return !this.isGraphClass(classes, c.name);
})
}

isGraphClass(classes, clazz) {
let sup = clazz;
let iterator = clazz;
while ((iterator = this.getSuperClazz(classes, iterator)) != "") {
sup = iterator;
if (sup == 'V' || sup == 'E') {
return true;
}
}
return sup == 'V' || sup == 'E';
}

getSuperClazz(classes, clazz) {
let clazzReturn = "";
for (var entry in classes) {
var name = classes[entry]['name'];
if (clazz == name) {
clazzReturn = classes[entry].superClass;
break;
}
}
return clazzReturn;
}


isVertexClass(classes, clazz) {
var sup = clazz;
var iterator = clazz;
while ((iterator = this.getSuperClazz(classes, iterator)) != "") {
sup = iterator;
}
return sup == 'V';
}

vertexClasses(classes) {
return classes.filter((c) => {
return this.isVertexClass(classes, c.name);
})
}

edgeClasses(classes) {
return classes.filter((c) => {
return this.isEdgeClass(classes, c.name);
})
}

isEdgeClass(classes, clazz) {
var sup = clazz;
var iterator = clazz;
while ((iterator = this.getSuperClazz(classes, iterator)) != "") {
sup = iterator;
}
return sup == 'E';
}
}

SchemaService
.parameters = [CommandService, FormatArrayPipe];


angular.module('schema.services', []).factory(`SchemaService`, downgradeInjectable(SchemaService));

export {SchemaService};
7 changes: 7 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SCHEMA_COMPONENTS from './schema';

const COMPONENTS = [
SCHEMA_COMPONENTS.name
]

export default COMPONENTS;
Loading

0 comments on commit 1406527

Please sign in to comment.