From ad6397b2947febb7ee5e7ece6ccf979c1d49edfc Mon Sep 17 00:00:00 2001 From: David Cruciani Date: Mon, 12 Feb 2024 15:33:47 +0100 Subject: [PATCH] chg: [website] history add input attr --- website/app/db_class/db.py | 4 +- website/app/home_core.py | 2 + website/app/static/js/case/case_tasks.js | 634 ------------------- website/app/static/js/history_view.js | 42 ++ website/app/templates/history.html | 26 +- website/app/templates/modules_config.html | 19 +- website/app/utils/init_modules.py | 7 +- website/install.sh | 12 + website/launch.sh | 1 - website/migrations/versions/183bf8fa2b87_.py | 32 + website/requirements.txt | 2 + 11 files changed, 118 insertions(+), 663 deletions(-) delete mode 100644 website/app/static/js/case/case_tasks.js create mode 100644 website/app/static/js/history_view.js create mode 100755 website/install.sh create mode 100644 website/migrations/versions/183bf8fa2b87_.py diff --git a/website/app/db_class/db.py b/website/app/db_class/db.py index 8c75980..493fcca 100644 --- a/website/app/db_class/db.py +++ b/website/app/db_class/db.py @@ -7,6 +7,7 @@ class Module(db.Model): description = db.Column(db.String) is_active = db.Column(db.Boolean, default=True) request_on_query = db.Column(db.Boolean, default=False) + input_attr = db.Column(db.String) def to_json(self): json_dict = { @@ -14,7 +15,8 @@ class Module(db.Model): "name": self.name, "description": self.description, "is_active": self.is_active, - "request_on_query": self.request_on_query + "request_on_query": self.request_on_query, + "input_attr": self.input_attr } return json_dict diff --git a/website/app/home_core.py b/website/app/home_core.py index cab2403..01deeab 100644 --- a/website/app/home_core.py +++ b/website/app/home_core.py @@ -79,6 +79,8 @@ def get_modules_config(): modules_list = [] for module in modules: loc_module = module.to_json() + if loc_module["input_attr"]: + loc_module["input_attr"] = json.loads(loc_module["input_attr"]) loc_module["config"] = [] mcs = Module_Config.query.filter_by(module_id=module.id).all() for mc in mcs: diff --git a/website/app/static/js/case/case_tasks.js b/website/app/static/js/case/case_tasks.js deleted file mode 100644 index 9e947db..0000000 --- a/website/app/static/js/case/case_tasks.js +++ /dev/null @@ -1,634 +0,0 @@ -import {display_toast} from '../toaster.js' -const { ref, nextTick, computed } = Vue -export default { - delimiters: ['[[', ']]'], - props: { - cases_info: Object, - status_info: Object, - users_in_case: Object, - edit_mode: Boolean, - task: Object, - key_loop: Number - }, - emits: ['edit_mode', 'task'], - setup(props, {emit}) { - Vue.onMounted(async () => { - select2_change(props.task.id) - - const targetElement = document.getElementById('editor_' + props.task.id) - editor = new Editor.EditorView({ - doc: "\n\n", - extensions: [Editor.basicSetup, Editor.markdown(),Editor.EditorView.updateListener.of((v) => { - if (v.docChanged) { - note_editor_render.value = editor.state.doc.toString() - } - })], - parent: targetElement - }) - - const allCollapses = document.getElementById('collapse' + props.task.id) - allCollapses.addEventListener('shown.bs.collapse', event => { - md.mermaid.init() - }) - is_mounted.value = true - }) - Vue.onUpdated(async () => { - select2_change(props.task.id) - // do not initialize mermaid before the page is mounted - if(is_mounted) - md.mermaid.init() - }) - - const is_mounted = ref(false) - const is_exporting = ref(false) - - const notes = ref(props.task.notes) - const note_editor_render = ref("") - let editor - const md = window.markdownit() - md.use(mermaidMarkdown.default) - - if(props.task.notes) - note_editor_render.value = props.task.notes - - - async function change_status(status, task){ - const res = await fetch( - '/case/' + task.case_id + '/change_task_status/'+task.id,{ - headers: { "X-CSRFToken": $("#csrf_token").val(), "Content-Type": "application/json" }, - method: "POST", - body: JSON.stringify({"status": status}) - } - ) - if(await res.status==200){ - task.last_modif = Date.now() - task.status_id=status - - if(props.status_info.status[status-1].name == 'Finished'){ - task.last_modif = Date.now() - task.completed = true - fetch('/case/complete_task/'+task.id) - }else{ - task.completed = false - } - } - await display_toast(res) - } - - async function take_task(task, current_user){ - const res = await fetch('/case/' + task.case_id + '/take_task/' + task.id) - - if( await res.status == 200){ - task.last_modif = Date.now() - task.is_current_user_assigned = true - task.users.push(current_user) - } - await display_toast(res) - } - - async function remove_assign_task(task, current_user){ - const res = await fetch('/case/' + task.case_id + '/remove_assignment/' + task.id) - - if( await res.status == 200){ - task.last_modif = Date.now() - task.is_current_user_assigned = false - - let index = -1 - - for(let i=0;i -1) - task.users.splice(index, 1) - } - await display_toast(res) - } - - - async function assign_user_task(){ - let users_select = $('#selectUser'+props.task.id).val() - if(users_select.length){ - const res_msg = await fetch( - '/case/' + props.task.case_id + '/assign_users/' + props.task.id,{ - headers: { "X-CSRFToken": $("#csrf_token").val(), "Content-Type": "application/json" }, - method: "POST", - body: JSON.stringify({"users_id": users_select}) - } - ) - if( await res_msg.status == 200){ - if(users_select.includes(props.cases_info.current_user.id.toString())){ - props.task.is_current_user_assigned = true - } - const res = await fetch('/case/' + props.task.case_id + '/get_assigned_users/' +props.task.id) - if(await res.status == 404){ - display_toast(res) - }else{ - let loc = await res.json() - props.task.users = loc - props.task.last_modif = Date.now() - emit('task', props.task) - } - } - await display_toast(res_msg) - } - } - - - async function remove_assigned_user(user_id){ - const res = await fetch( - '/case/' + props.task.case_id + '/remove_assigned_user/' + props.task.id,{ - headers: { "X-CSRFToken": $("#csrf_token").val(), "Content-Type": "application/json" }, - method: "POST", - body: JSON.stringify({"user_id": user_id}) - } - ) - - if( await res.status == 200){ - props.task.last_modif = Date.now() - - let index = -1 - for(let i=0;i -1) - props.task.users.splice(index, 1) - } - await display_toast(res) - } - - - async function delete_task(task, task_array){ - const res = await fetch('/case/' + task.case_id + '/delete_task/' + task.id) - - if( await res.status == 200){ - let index = task_array.indexOf(task) - if(index > -1) - task_array.splice(index, 1) - } - await display_toast(res) - } - - async function edit_note(task){ - task.last_modif = Date.now() - emit('edit_mode', true) - - const res = await fetch('/case/' + task.case_id + '/get_note/' + task.id) - let loc = await res.json() - task.notes = loc["note"] - - const targetElement = document.getElementById('editor1_' + props.task.id) - editor = new Editor.EditorView({ - doc: task.notes, - extensions: [Editor.basicSetup, Editor.markdown(),Editor.EditorView.updateListener.of((v) => { - if (v.docChanged) { - note_editor_render.value = editor.state.doc.toString() - } - })], - parent: targetElement - }) - - } - - async function modif_note(task){ - let notes_loc = editor.state.doc.toString() - if(notes_loc.trim().length == 0){ - notes_loc = notes_loc.trim() - } - const res_msg = await fetch( - '/case/' + task.case_id + '/modif_note/' + task.id,{ - headers: { "X-CSRFToken": $("#csrf_token").val(), "Content-Type": "application/json" }, - method: "POST", - body: JSON.stringify({"task_id": task.id.toString(), "notes": notes_loc}) - } - ) - - if(await res_msg.status == 200){ - emit('edit_mode', false) - task.last_modif = Date.now() - task.notes = notes_loc - notes.value = notes_loc - await nextTick() - - if(!notes_loc){ - const targetElement = document.getElementById('editor_' + props.task.id) - if(targetElement.innerHTML === ""){ - editor = new Editor.EditorView({ - doc: "\n\n", - extensions: [Editor.basicSetup, Editor.markdown(),Editor.EditorView.updateListener.of((v) => { - if (v.docChanged) { - note_editor_render.value = editor.state.doc.toString() - } - })], - parent: targetElement - }) - } - } - } - await display_toast(res_msg) - } - - - async function add_file(task){ - let files = document.getElementById('formFileMultiple'+task.id).files - - let formData = new FormData(); - for(let i=0;i -1) - task.files.splice(index, 1) - } - await display_toast(res) - } - - async function complete_task(task){ - const res = await fetch('/case/complete_task/'+task.id) - if (await res.status == 200){ - task.last_modif = Date.now() - task.completed = !task.completed - let status = task.status_id - if(props.status_info.status[task.status_id -1].name == 'Finished'){ - for(let i in props.status_info.status){ - if(props.status_info.status[i].name == 'Created') - task.status_id = props.status_info.status[i].id - } - if(task.status_id == status) - task.status_id = 1 - - }else{ - for(let i in props.status_info.status){ - if(props.status_info.status[i].name == 'Finished'){ - task.status_id = props.status_info.status[i].id - break - } - } - } - let index = props.cases_info.tasks.indexOf(task) - if(index > -1) - props.cases_info.tasks.splice(index, 1) - } - await display_toast(res) - } - - async function notify_user(user_id){ - const res = await fetch( - '/case/' + props.task.case_id + '/task/' + props.task.id + '/notify_user',{ - headers: { "X-CSRFToken": $("#csrf_token").val(), "Content-Type": "application/json" }, - method: "POST", - body: JSON.stringify({"task_id": props.task.id, "user_id": user_id}) - } - ) - await display_toast(res) - } - - function formatNow(dt) { - return moment.utc(dt).from(moment.utc()) - } - - function endOf(dt){ - return moment.utc(dt).endOf().from(moment.utc()) - } - - - function present_user_in_task(task_user_list, user){ - let index = -1 - - for(let i=0;i - -
- - - - - - - - -
- - - - -
-
-
-
-
-
Assign
- - -
- -
-
Remove assign
-
- [[user.first_name]] [[user.last_name]] - - -
-
-
-
-
-
Change Status
-
-
- -
-
-
-
-
-
-
-
Tool/Url
-
-
- [[task.url]] -
-
-
-
-
Connectors
-
- -
-
-
-
-
-
-
Files
-
-
- - -
-
- -
-
-
-
-
-
-
Notes
-
-
- - -
-
- -
-
-
-
-
- ` -} \ No newline at end of file diff --git a/website/app/static/js/history_view.js b/website/app/static/js/history_view.js new file mode 100644 index 0000000..aa17b9d --- /dev/null +++ b/website/app/static/js/history_view.js @@ -0,0 +1,42 @@ + +const { ref, nextTick } = Vue +export default { + name: "History_view", + delimiters: ['[[', ']]'], + props: { + history: Object, + key_loop: Number + }, + setup(props) { + + + + return { + + } + }, + template: ` + + + ` +} \ No newline at end of file diff --git a/website/app/templates/history.html b/website/app/templates/history.html index 92b0cb0..871ec52 100644 --- a/website/app/templates/history.html +++ b/website/app/templates/history.html @@ -12,27 +12,7 @@
@@ -43,8 +23,12 @@