Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
necessary fixes: TODO.md
  • Loading branch information
roper79 committed Dec 25, 2018
1 parent 6c957c1 commit c2465ab
Show file tree
Hide file tree
Showing 19 changed files with 777 additions and 585 deletions.
6 changes: 4 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- refactor update a delete v UFO-A na postData
- zkusit abstrahovat lock na withLock
- opravit mazani entit na serveru
- mazani grafiky entit
- UFO-B mazani elementu: pridat mazani grafiky

- refactor to https://www.primefaces.org/primereact
49 changes: 29 additions & 20 deletions app/db/general.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
// @flow

export const requestFailedMsg = "Request to server failed";
export function ajax(url: string, method: "POST" | "GET", data: any): Promise<any> {
const params = {
method,
body: data ? JSON.stringify(data) : null,
headers: {
"Content-Type": "application/json"
},
credentials: "same-origin"
};

export function getData(url: string): Promise<any> {
return new Promise((resolve, reject) => {
$.get(url, (data: any, status: String) => {
if (status !== "success") {
console.error(status);
reject(status);
} else {
resolve(data);
}
}).fail(() => reject(requestFailedMsg));
fetch(url, params).then(
response => {
if (response.status !== 200) {
reject(response.statusText);
} else {
if (method === "GET") {
resolve(response.json());
} else {
resolve();
}
}
},
error => reject(error.message)
);
});
}

export function getData(url: string): Promise<any> {
return ajax(url, "GET", null);
}

export function postData(url: string, data: any): Promise<any> {
return new Promise((resolve, reject) => {
$.post(url, data, (response) => {
if (response.error) {
console.error(response.error);
reject(response.error);
} else {
resolve(response.result);
}
}).fail(() => reject(requestFailedMsg));
});
return ajax(url, "POST", data);
}



84 changes: 34 additions & 50 deletions app/db/ufoa.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
// @flow

import type { Id, Label } from '../metamodel/general';
import type { UfoaEntity, Generalisation, GSet, Association, AssocType, AssocMeta, Connection, UfoaModel } from '../metamodel/ufoa';
import type { Id } from '../metamodel/general';
import type { UfoaEntity, Generalisation, GSet, Association, UfoaModel } from '../metamodel/ufoa';
import * as ufoaMeta from '../metamodel/ufoa';
import * as urls from "../urls";
import * as ufoaModel from '../model/ufoa';
import { getData, postData, requestFailedMsg } from './general';
import { getData, postData } from './general';

var model: UfoaModel = ufoaMeta.emptyModel;

// Model

export function loadModel(): Promise<any> {
return new Promise((resolve, reject) => {
getData(urls.baseURL + urls.ufoaGetModel).then(data => {
model = data;
resolve(data);
}, (error) => reject(error));
getData(urls.baseURL + urls.ufoaGetModel).then(
data => {
model = data;
resolve(data);
},
error => reject(error));
});
}

Expand Down Expand Up @@ -48,27 +50,21 @@ export function updateEntity(updatedEntity: UfoaEntity): Promise<any> {
if (validity.errors) {
reject("Entity update failed: " + validity.errors);
} else {
$.post(urls.baseURL + urls.ufoaEntityUpdate, { entity: JSON.stringify(updatedEntity) }, (response) => {
if (response.error) {
reject(response.error);
} else {
resolve(response.result);
}
}).fail(() => reject(requestFailedMsg));
postData(urls.baseURL + urls.ufoaEntityUpdate, { entity: JSON.stringify(updatedEntity) }).then(
() => resolve(),
error => reject(error)
);
}
});
}

export function deleteEntity(e_id: Id): Promise<any> {
return new Promise((resolve, reject) => {
ufoaModel.deleteEntity(model, e_id);
$.post(urls.baseURL + urls.ufoaEntityDelete, { e_id }, (response) => {
if (response.error) {
reject(response.error);
} else {
resolve(response.result);
}
}).fail(() => reject(requestFailedMsg));
model = ufoaModel.deleteEntity(model, e_id);
postData(urls.baseURL + urls.ufoaEntityDelete, { e_id }).then(
() => resolve(),
error => reject(error)
);
});
}

Expand Down Expand Up @@ -96,27 +92,21 @@ export function updateGeneralisation(updatedGeneralisation: Generalisation): Pro
if (validity.errors) {
console.error("Generalisation update failed: " + validity.errors);
} else {
$.post(urls.baseURL + urls.generalisationUpdate, { generalisation: JSON.stringify(updatedGeneralisation) }, (response) => {
if (response.error) {
reject(response.error);
} else {
resolve(response.result);
}
}).fail(() => reject(requestFailedMsg));
postData(urls.baseURL + urls.generalisationUpdate, { generalisation: JSON.stringify(updatedGeneralisation) }).then(
() => resolve(),
error => reject(error)
);
}
});
}

export function deleteGeneralisation(g_id: Id): Promise<any> {
return new Promise((resolve, reject) => {
ufoaModel.deleteGeneralisation(model, g_id);
$.post(urls.baseURL + urls.ufoaGeneralisationDelete, { g_id }, (response) => {
if (response.error) {
reject(response.error);
} else {
resolve(response.result);
}
}).fail(() => reject(requestFailedMsg));
postData(urls.baseURL + urls.ufoaGeneralisationDelete, { g_id }).then(
() => resolve(),
error => reject(error)
);
});
}

Expand Down Expand Up @@ -144,27 +134,21 @@ export function updateAssociation(updatedAssociation: Association): Promise<any>
if (validity.errors) {
console.error("Association update failed: " + validity.errors);
} else {
$.post(urls.baseURL + urls.associationUpdate, { association: JSON.stringify(updatedAssociation) }, (response) => {
if (response.error) {
reject(response.error);
} else {
resolve(response.result);
}
}).fail(() => reject(requestFailedMsg));
postData(urls.baseURL + urls.associationUpdate, { association: JSON.stringify(updatedAssociation) }).then(
() => resolve(),
error => reject(error)
);
}
});
}

export function deleteAssociation(a_id: Id): Promise<any> {
return new Promise((resolve, reject) => {
ufoaModel.deleteAssociation(model, a_id);
$.post(urls.baseURL + urls.ufoaAssociationDelete, { a_id }, (response) => {
if (response.error) {
reject(response.error);
} else {
resolve(response.result);
}
}).fail(() => reject(requestFailedMsg));
postData(urls.baseURL + urls.ufoaAssociationDelete, { a_id }).then(
() => resolve(),
error => reject(error)
);
});
}

Expand Down
24 changes: 14 additions & 10 deletions app/view/ufoa/dialogs/entityDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ type State = {
};

function commitEntity(nodes: any, e: UfoaEntity) {
ufoaDB.updateEntity(e).then((response) => {
nodes.update({ id: e.e_id, label: ufoaMeta.entityStr(e) });
panels.hideDialog();
panels.displayInfo("Entity saved.");
}, (error) => panels.displayError("Entity save failed: " + error));
ufoaDB.updateEntity(e).then(
() => {
nodes.update({ id: e.e_id, label: ufoaMeta.entityStr(e) });
panels.hideDialog();
panels.displayInfo("Entity saved.");
},
error => panels.displayError("Entity save failed: " + error));
}

class UfoaNodeForm extends React.Component<Props, State> {
Expand Down Expand Up @@ -66,11 +68,13 @@ class UfoaNodeForm extends React.Component<Props, State> {
delete = (event) => {
let nodes: any = this.props.ufoaVisModel.nodes;
let e_id = this.props.ufoaEntity.e_id;
ufoaDB.deleteEntity(e_id).then((response) => {
nodes.remove({ id: e_id });
panels.hideDialog();
panels.displayInfo("Entity deleted.");
}, (error) => panels.displayError("Entity delete failed: " + error));
ufoaDB.deleteEntity(e_id).then(
() => {
nodes.remove({ id: e_id });
panels.hideDialog();
panels.displayInfo("Entity deleted.");
},
error => panels.displayError("Entity delete failed: " + error));
}

renderEntityType() {
Expand Down
8 changes: 0 additions & 8 deletions data/ufoa-graphics.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,5 @@
"e120": {
"x": -1973,
"y": -1071
},
"e121": {
"x": -1897,
"y": -1318
},
"e122": {
"x": -267,
"y": -9082
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,5 @@
"e120": {
"x": -1973,
"y": -1071
},
"e121": {
"x": -1897,
"y": -1318
},
"e122": {
"x": -267,
"y": -9082
}
}
23 changes: 2 additions & 21 deletions data/ufoa.json
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@
},
{
"e_id": "e121",
"e_type": "mode",
"e_name": "Follow-up Results"
"e_type": "kind",
"e_name": "xxx"
}
],
"generalisations": [
Expand Down Expand Up @@ -2888,25 +2888,6 @@
}
}
},
{
"a_id": "a80",
"a_type": "characterization",
"a_meta": "",
"a_label": "",
"a_connection1": {
"e_id": "e120",
"mult": {
"lower": 1,
"upper": 1
}
},
"a_connection2": {
"e_id": "e121",
"mult": {
"lower": 1
}
}
},
{
"a_id": "a81",
"a_type": "mediation",
Expand Down
Loading

0 comments on commit c2465ab

Please sign in to comment.