Skip to content

Commit

Permalink
Merge pull request #44 from averkij/t/master/ui
Browse files Browse the repository at this point in the history
Add files and alignments deletion.
  • Loading branch information
averkij committed Mar 16, 2021
2 parents b8035b4 + 1c3311b commit 81e4564
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 37 deletions.
49 changes: 46 additions & 3 deletions be/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,18 +383,27 @@ def init_user_db(username):
db.execute(
'create table documents(id integer primary key, guid varchar, lang varchar, name varchar)')
db.execute(
'create table alignments(id integer primary key, guid varchar, guid_from varchar, guid_to varchar, name varchar, state integer, curr_batches integer, total_batches integer)')
'create table alignments(id integer primary key, guid varchar, guid_from varchar, guid_to varchar, name varchar, state integer, curr_batches integer, total_batches integer, deleted integer default 0 NOT NULL)')


def alignment_exists(username, guid_from, guid_to):
"""Check if alignment already exists"""
db_path = os.path.join(con.UPLOAD_FOLDER, username, con.USER_DB_NAME)
with sqlite3.connect(db_path) as db:
cur = db.execute("select * from alignments where guid_from=:guid_from and guid_to=:guid_to", {
cur = db.execute("select * from alignments where guid_from=:guid_from and guid_to=:guid_to and deleted <> 1", {
"guid_from": guid_from, "guid_to": guid_to})
return bool(cur.fetchone())


def alignment_guid_exists(username, guid):
"""Check if alignment already exists by alignment guid"""
db_path = os.path.join(con.UPLOAD_FOLDER, username, con.USER_DB_NAME)
with sqlite3.connect(db_path) as db:
cur = db.execute(
"select * from alignments where guid=:guid", {"guid": guid})
return bool(cur.fetchone())


def register_alignment(username, guid, guid_from, guid_to, name, total_batches):
"""Register new alignment in database"""
db_path = os.path.join(con.UPLOAD_FOLDER, username, con.USER_DB_NAME)
Expand Down Expand Up @@ -434,6 +443,13 @@ def update_batch_progress(db_path, batch_id):
"insert or ignore into batches (batch_id, insert_ts) values (?, datetime('now'))", (batch_id,))


def delete_alignment(user_db_path, guid):
"""Mark alignment as deleted"""
with sqlite3.connect(user_db_path) as db:
db.execute('update alignments set deleted = 1 where guid=:guid', {
"guid": guid})


def get_batches_count(db_path):
"""Get amount of already processed batches"""
with sqlite3.connect(db_path) as db:
Expand Down Expand Up @@ -473,6 +489,15 @@ def file_exists(username, lang, name):
return bool(cur.fetchone())


def file_exists_by_guid(username, guid):
"""Check if file already exists by guid"""
db_path = os.path.join(con.UPLOAD_FOLDER, username, con.USER_DB_NAME)
with sqlite3.connect(db_path) as db:
cur = db.execute(
"select * from documents where guid=:guid", {"guid": guid})
return bool(cur.fetchone())


def register_file(username, lang, name):
"""Register new file in database"""
db_path = os.path.join(con.UPLOAD_FOLDER, username, con.USER_DB_NAME)
Expand All @@ -482,6 +507,23 @@ def register_file(username, lang, name):
"guid": guid, "lang": lang, "name": name})


def delete_document(username, guid, lang, filename):
"""Delete uploaded document and clean database"""
raw_path = os.path.join(con.UPLOAD_FOLDER, username,
con.RAW_FOLDER, lang, filename)
proxy_path = os.path.join(
con.UPLOAD_FOLDER, username, con.PROXY_FOLDER, lang, filename)

if os.path.isfile(raw_path):
os.remove(raw_path)
if os.path.isfile(proxy_path):
os.remove(proxy_path)

db_path = os.path.join(con.UPLOAD_FOLDER, username, con.USER_DB_NAME)
with sqlite3.connect(db_path) as db:
db.execute('delete from documents where guid=:guid', {"guid": guid})


def get_documents_list(username, lang=None):
"""Get documents list by language code"""
db_path = os.path.join(con.UPLOAD_FOLDER, username, con.USER_DB_NAME)
Expand Down Expand Up @@ -525,7 +567,8 @@ def get_alignments_list(username, lang_from, lang_to):
join documents d_from on d_from.guid=a.guid_from
join documents d_to on d_to.guid=a.guid_to
where
d_from.lang=:lang_from and d_to.lang=:lang_to""", {
d_from.lang=:lang_from and d_to.lang=:lang_to
and deleted <> 1""", {
"lang_from": lang_from, "lang_to": lang_to}).fetchall()
return res

Expand Down
29 changes: 29 additions & 0 deletions be/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def create_alignment(username):
if helper.alignment_exists(username, id_from, id_to):
return ('', 200)

if not helper.file_exists_by_guid(username, id_from) or not helper.file_exists_by_guid(username, id_to):
return ('', 400)

batch_size = config.DEFAULT_BATCHSIZE
file_from, lang_from = helper.get_fileinfo(username, id_from)
file_to, lang_to = helper.get_fileinfo(username, id_to)
Expand Down Expand Up @@ -175,6 +178,32 @@ def create_alignment(username):
return ('', 200)


@app.route("/items/<username>/alignment/delete", methods=["POST"])
def delete_alignment(username):
"""Mark existed alignment as deleted"""
align_guid = request.form.get("align_guid", '')

if not helper.alignment_guid_exists(username, align_guid):
return ('', 400)

user_db_path = os.path.join(con.UPLOAD_FOLDER, username, con.USER_DB_NAME)
helper.delete_alignment(user_db_path, align_guid)

return ('', 200)


@app.route("/items/<username>/raw/delete", methods=["POST"])
def delete_document(username):
"""Delete uploaded file"""
guid = request.form.get("guid", '')
lang = request.form.get("lang", '')
filename = request.form.get("filename", '')

helper.delete_document(username, guid, lang, filename)

return ('', 200)


@app.route("/items/<username>/alignment/align", methods=["POST"])
def start_alignment(username):
"""Align two splitted documents"""
Expand Down
20 changes: 20 additions & 0 deletions fe/src/common/api.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,26 @@ export const ItemsService = {
form
);
},
deleteAlignment(params) {
let form = new FormData();
form.append("align_guid", params.guid);
return ApiService.post(
"items",
`${params.username}/alignment/delete`,
form
);
},
deleteDocument(params) {
let form = new FormData();
form.append("guid", params.guid);
form.append("lang", params.langCode);
form.append("filename", params.filename);
return ApiService.post(
"items",
`${params.username}/raw/delete`,
form
);
},
editProcessing(params) {
let form = new FormData();
form.append("text", params.text);
Expand Down
49 changes: 49 additions & 0 deletions fe/src/components/ConfirmDeleteDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<v-dialog v-model="show" max-width="500px">
<v-card>
<v-card-title>
Please, confirm
</v-card-title>
<v-card-text class="text-body-1 mt-2">Do you realy want do delete <span class="font-weight-bold">{{this.itemName}}</span>?</v-card-text>
<v-card-actions class="mt-5">
<v-btn color="primary" text @click="show=false">
Close
</v-btn>
<v-spacer></v-spacer>
<v-btn color="red" dark @click="confirmDelete">
Delete
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>

<script>
export default {
name: "ConfirmDeleteDialog",
props: {
value: Boolean,
itemName: String
},
data() {
return {
}
},
methods: {
confirmDelete() {
this.show = false;
this.$emit('confirmDelete')
},
},
computed: {
show: {
get() {
return this.value
},
set(value) {
this.$emit('input', value)
}
}
}
}
</script>
80 changes: 56 additions & 24 deletions fe/src/components/RawPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,83 @@
<!-- <v-divider></v-divider> -->
<v-list class="pa-0">
<v-list-item-group mandatory color="gray">
<v-list-item v-for="(item, i) in items[info.langCode]" :key="i"
@change="selectAndLoadPreview(info.langCode, item.name, item.guid)">
<v-list-item
v-for="(item, i) in items[info.langCode]"
:key="i"
@change="selectAndLoadPreview(info.langCode, item.name, item.guid)"
@mouseover="hover_index = i"
@mouseleave="hover_index = -1"
>
<v-list-item-icon>
<v-icon>mdi-text-box-outline</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title v-text="item.name"></v-list-item-title>
<!-- {{item.guid}} -->
<div>{{item.name}}<v-chip v-if="item.has_proxy" class="ml-2" small label color="blue" text-color="white">translated</v-chip></div>
</v-list-item-content>
<v-icon v-if="item.has_proxy">mdi-translate</v-icon>
<v-icon v-show="hover_index == i" class="ml-2" @click.stop.prevent="currentItem=item, showConfirmDeleteDialog=true">mdi-close</v-icon>
</v-list-item>
</v-list-item-group>
</v-list>
<ConfirmDeleteDialog v-model="showConfirmDeleteDialog"
:itemName=currentItem.name
@confirmDelete="confirmDelete" />
<v-divider></v-divider>
<v-card-title>Upload</v-card-title>
<v-card-text>Upload raw {{ info.name }} document in txt format.</v-card-text>
<v-card-text
>Upload raw {{ info.name }} document in txt format.</v-card-text
>
<v-card-actions>
<v-file-input outlined dense accept=".txt" @change="onFileChange($event, info.langCode)">
<v-file-input
outlined
dense
accept=".txt"
@change="onFileChange($event, info.langCode)"
>
</v-file-input>
</v-card-actions>
<v-divider></v-divider>
<v-card-actions>
<v-btn @click="uploadFile(info.langCode)" :loading="isLoading.upload[info.langCode]"
:disabled="isLoading.upload[info.langCode]">
<v-btn
@click="uploadFile(info.langCode)"
:loading="isLoading.upload[info.langCode]"
:disabled="isLoading.upload[info.langCode]"
>
Upload
</v-btn>
</v-card-actions>
</v-card>
</template>

<script>
export default {
name: "RawPanel",
props: ["info", "isLoading", "items"],
methods: {
onFileChange(event, langCode) {
this.$emit('onFileChange', event, langCode)
},
uploadFile(langCode) {
this.$emit('uploadFile', langCode)
},
selectAndLoadPreview(langCode, item, id) {
this.$emit('selectAndLoadPreview', langCode, item, id)
}
import ConfirmDeleteDialog from "@/components/ConfirmDeleteDialog"
export default {
name: "RawPanel",
props: ["info", "isLoading", "items"],
data() {
return {
hover_index: -1,
showConfirmDeleteDialog: false,
currentItem: {"name": ""}
};
},
methods: {
confirmDelete() {
this.$emit('performDelete', this.currentItem, this.info.langCode);
},
onFileChange(event, langCode) {
this.$emit("onFileChange", event, langCode);
},
uploadFile(langCode) {
this.$emit("uploadFile", langCode);
},
selectAndLoadPreview(langCode, item, id) {
this.$emit("selectAndLoadPreview", langCode, item, id);
},
computed: {}
};
},
computed: {},
components: {
ConfirmDeleteDialog
}
};
</script>
1 change: 0 additions & 1 deletion fe/src/components/RecalculateBatchDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
this.show = false;
this.$emit('recalculateBatch', this.batch_id, this.shift)
},
},
computed: {
show: {
Expand Down
2 changes: 2 additions & 0 deletions fe/src/store/actions.type.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const LOGIN = "login";
export const LOGOUT = "logout";

export const UPLOAD_FILES = "upload_files";
export const DELETE_DOCUMENT = "delete_document";

export const INIT_USERSPACE = "init_userspace";
export const FETCH_ITEMS = "fetch_items";
Expand All @@ -18,6 +19,7 @@ export const GET_CONFLICT_SPLITTED_TO = "get_conflict_splitted_to";
export const GET_CONFLICT_FLOW_TO = "get_conflict_flow_to";

export const CREATE_ALIGNMENT = "create_alignment"
export const DELETE_ALIGNMENT = "delete_alignment"
export const STOP_ALIGNMENT = "stop_alignment";

export const EDIT_PROCESSING = "edit_processing";
Expand Down
17 changes: 17 additions & 0 deletions fe/src/store/items.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
FETCH_ITEMS,
FETCH_ITEMS_PROCESSING,
UPLOAD_FILES,
DELETE_DOCUMENT,
DOWNLOAD_SPLITTED,
DOWNLOAD_PROCESSING,
GET_SPLITTED,
Expand All @@ -22,6 +23,7 @@ import {
STOP_ALIGNMENT,
ALIGN_SPLITTED,
CREATE_ALIGNMENT,
DELETE_ALIGNMENT,
GET_CONFLICT_SPLITTED_FROM,
GET_CONFLICT_SPLITTED_TO,
GET_CONFLICT_FLOW_TO
Expand Down Expand Up @@ -104,6 +106,7 @@ export const actions = {
const {
data
} = await ItemsService.getSplitted(params);
console.log(data)
context.commit(SET_SPLITTED, {
data: data,
langCode: params.langCode
Expand Down Expand Up @@ -214,6 +217,20 @@ export const actions = {
() => {
console.log("alignment creation error")
});
},
async [DELETE_ALIGNMENT](context, params) {
await ItemsService.deleteAlignment(params).then(() => {
},
() => {
console.log("alignment deletion error")
});
},
async [DELETE_DOCUMENT](context, params) {
await ItemsService.deleteDocument(params).then(() => {
},
() => {
console.log("document deletion error")
});
}
};

Expand Down

0 comments on commit 81e4564

Please sign in to comment.