From 7d2b2ced65bb8d998e68f7a4fdf46d33259d9b23 Mon Sep 17 00:00:00 2001 From: Vince Date: Mon, 14 Dec 2020 17:56:42 +0100 Subject: [PATCH 01/74] changed title --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e26977..5486005 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# pptx-tool +# knowlix with mongodb as backend Microservice to autmatically create onboarding slides From ea740de78ac0ee9f33fa9800b61101fa58558102 Mon Sep 17 00:00:00 2001 From: Vince Date: Mon, 14 Dec 2020 17:57:25 +0100 Subject: [PATCH 02/74] new title --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5486005..e679a39 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# knowlix with mongodb as backend +# knowlix - mongodb Microservice to autmatically create onboarding slides From e4b09fec050174cb7a2456ada91f6db24bece59c Mon Sep 17 00:00:00 2001 From: Vince Date: Mon, 14 Dec 2020 20:27:27 +0100 Subject: [PATCH 03/74] updated gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e8a7ad9..99f780e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ data.json *.pptx /backend/output *.pyc -*.log \ No newline at end of file +*.log +mongodb/ \ No newline at end of file From 00ea1b513a135663fea98c641abc68f708ac6bf0 Mon Sep 17 00:00:00 2001 From: Vince Date: Sat, 19 Dec 2020 20:13:00 +0100 Subject: [PATCH 04/74] cleansing --- backend/clean_output.py | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 backend/clean_output.py diff --git a/backend/clean_output.py b/backend/clean_output.py deleted file mode 100644 index 2e043e5..0000000 --- a/backend/clean_output.py +++ /dev/null @@ -1,7 +0,0 @@ -import os - -folder = os.path.join(os.getcwd(),'backend/output') -filelist = [f for f in os.listdir(folder)if f.endswith(".pptx")] - -for f in filelist: - os.remove(os.path.join(folder,f)) From 8e8548ff8f81b90bb25bf9c2dfc98a58c110597a Mon Sep 17 00:00:00 2001 From: Vince Date: Sat, 19 Dec 2020 20:13:34 +0100 Subject: [PATCH 05/74] monngodb backend + ws --- .gitignore | 3 +- backend/.gitignore | 1 + backend/api.py | 3 +- backend/req.txt | 27 ++-- backend/server.py | 8 +- celery/.gitignore | 1 + celery/req.txt | 2 +- celery/server.py | 13 +- celery/worker.py | 10 +- docker-compose.yml | 31 ++-- frontend/nuxt-fe/components/DownloadItem.vue | 9 +- frontend/nuxt-fe/components/alertJob.vue | 2 +- frontend/nuxt-fe/nuxt.config.js | 2 + frontend/nuxt-fe/pages/index.vue | 19 ++- frontend/nuxt-fe/store/index.js | 13 +- mongo-startup/initiate_replica.sh | 44 +++++ mongo-stream/.gitignore | 1 + mongo-stream/Dockerfile | 9 ++ mongo-stream/req.txt | 4 + mongo-stream/server.py | 108 +++++++++++++ v1.docker-compose.yml | 161 +++++++++++++++++++ 21 files changed, 420 insertions(+), 51 deletions(-) create mode 100644 backend/.gitignore create mode 100644 celery/.gitignore create mode 100755 mongo-startup/initiate_replica.sh create mode 100644 mongo-stream/.gitignore create mode 100644 mongo-stream/Dockerfile create mode 100644 mongo-stream/req.txt create mode 100644 mongo-stream/server.py create mode 100644 v1.docker-compose.yml diff --git a/.gitignore b/.gitignore index 99f780e..90a3384 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ data.json /backend/output *.pyc *.log -mongodb/ \ No newline at end of file +mongodb/ +db-backup/ \ No newline at end of file diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000..ae412d6 --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1 @@ +env/ \ No newline at end of file diff --git a/backend/api.py b/backend/api.py index 1864dab..bbc057f 100644 --- a/backend/api.py +++ b/backend/api.py @@ -9,6 +9,7 @@ from pptx import Presentation from server import celery import json +from datetime import datetime file_path = "master.pptx" @@ -64,7 +65,7 @@ async def deliver_pptx(pptx: PPTX): sections = pptx.sections kwargs ={ 'sections':sections, - 'downloadStatus': 'ready' + } diff --git a/backend/req.txt b/backend/req.txt index 1efa76d..023c0a5 100644 --- a/backend/req.txt +++ b/backend/req.txt @@ -1,27 +1,26 @@ -certifi==2020.6.20 -click==7.1.2 -fastapi==0.61.2 -h11==0.11.0 -lxml==4.6.1 -Pillow==8.0.1 -pydantic==1.7.2 -python-pptx==0.6.18 -starlette==0.13.6 -typing==3.7.4.3 -uvicorn==0.12.2 -XlsxWriter==1.3.7 aiofiles==0.6.0 amqp==5.0.2 billiard==3.6.3.0 celery==5.0.3 +certifi==2020.6.20 click==7.1.2 click-didyoumean==0.0.3 click-plugins==1.1.1 click-repl==0.1.6 +fastapi==0.61.2 +h11==0.11.0 kombu==5.0.2 +lxml==4.6.1 +Pillow==8.0.1 prompt-toolkit==3.0.8 +pydantic==1.7.2 +pymongo==3.11.2 +python-pptx==0.6.18 pytz==2020.4 -redis==3.5.3 six==1.15.0 +starlette==0.13.6 +typing==3.7.4.3 +uvicorn==0.12.2 vine==5.0.0 -wcwidth==0.2.5 \ No newline at end of file +wcwidth==0.2.5 +XlsxWriter==1.3.7 diff --git a/backend/server.py b/backend/server.py index fcb32e6..b71325e 100644 --- a/backend/server.py +++ b/backend/server.py @@ -2,10 +2,14 @@ from celery import Celery CELERY_BROKER_URL = os.getenv("RABBITMQ") -CELERY_RESULT_BACKEND = os.getenv("REDISSERVER") +CELERY_RESULT_BACKEND = os.getenv("MONGODB") celery = Celery("worker", backend=CELERY_RESULT_BACKEND, broker=CELERY_BROKER_URL) celery.conf.update( - result_extended=True + result_extended=True, + mongodb_backend_settings={ + 'database': 'taskdb', + 'taskmeta_collection': 'ta', + } ) diff --git a/celery/.gitignore b/celery/.gitignore new file mode 100644 index 0000000..ae412d6 --- /dev/null +++ b/celery/.gitignore @@ -0,0 +1 @@ +env/ \ No newline at end of file diff --git a/celery/req.txt b/celery/req.txt index 2a2f26c..f1fc5d9 100644 --- a/celery/req.txt +++ b/celery/req.txt @@ -9,9 +9,9 @@ kombu==5.0.2 lxml==4.6.2 Pillow==8.0.1 prompt-toolkit==3.0.8 +pymongo==3.11.2 python-pptx==0.6.18 pytz==2020.4 -redis==3.5.3 six==1.15.0 vine==5.0.0 wcwidth==0.2.5 diff --git a/celery/server.py b/celery/server.py index 1c2b195..e39ac1d 100644 --- a/celery/server.py +++ b/celery/server.py @@ -1,14 +1,17 @@ import os from celery import Celery -import redis + CELERY_BROKER_URL = os.getenv("RABBITMQ") -CELERY_RESULT_BACKEND = os.getenv("REDISSERVER") +CELERY_RESULT_BACKEND = os.getenv("MONGODB") app = Celery("worker", backend=CELERY_RESULT_BACKEND, - broker=CELERY_BROKER_URL) + broker=CELERY_BROKER_URL) app.conf.update( result_extended=True, - - ) + mongodb_backend_settings={ + 'database': 'taskdb', + 'taskmeta_collection': 'ta', + } +) diff --git a/celery/worker.py b/celery/worker.py index 098eedd..919d241 100644 --- a/celery/worker.py +++ b/celery/worker.py @@ -5,24 +5,22 @@ from time import sleep from celery.exceptions import Ignore from pptx import Presentation -import redis + from pptx_handler import create_pptx import json -CELERY_BROKER_URL = os.getenv("RABBITMQ") -CELERY_RESULT_BACKEND = os.getenv("REDISSERVER") + from server import app @app.task(name='pptx', bind=True, max_retries=3) -def generate_pptx(self, sections, downloadStatus): +def generate_pptx(self, sections): try: pptx_path = "master.pptx" task_id=self.request.id - # task_prefix = "celery-task-meta-" - # task_str = task_prefix + task_id + pres= Presentation(pptx_path) diff --git a/docker-compose.yml b/docker-compose.yml index 9abd112..fcc0bb6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,18 +31,33 @@ services: - ./celery/server.py:/celery/server.py - ./celery/worker.py:/celery/worker.py environment: - REDISSERVER: redis://redis + MONGODB: mongodb://mongodb RABBITMQ: pyamqp://rabbitmq depends_on: - - redis + - mongodb - rabbitmq + + mongo-watcher: + container_name: mongo-watcher + restart: on-failure + build: ./mongo-watcher/ + entrypoint: + - /usr/app/start.sh + environment: + MONGODB: mongodb://mongodb + + ports: + - "3333:3333" + depends_on: + - mongodb + - celery apihub: build: ./backend/ container_name: apihub restart: on-failure environment: - REDISSERVER: redis://redis + MONGODB: mongodb://mongodb RABBITMQ: pyamqp://rabbitmq volumes: - type: bind @@ -68,14 +83,10 @@ services: ports: - "8000:8000" depends_on: - - redis + - mongodb - rabbitmq - redis: - container_name: redis - image: redis:6.0-buster - ports: - - "6379:6379" + rabbitmq: container_name: rabbitmq @@ -90,7 +101,7 @@ services: ports: - "5555:5555" depends_on: - - redis + - mongodb - rabbitmq - celery diff --git a/frontend/nuxt-fe/components/DownloadItem.vue b/frontend/nuxt-fe/components/DownloadItem.vue index 19faf80..ad09721 100644 --- a/frontend/nuxt-fe/components/DownloadItem.vue +++ b/frontend/nuxt-fe/components/DownloadItem.vue @@ -99,12 +99,12 @@ - + -
+
-
- {{ task.taskID }} +
+ {{ index + 1}}
@@ -149,6 +149,7 @@ class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium" > Download diff --git a/frontend/nuxt-fe/components/alertJob.vue b/frontend/nuxt-fe/components/alertJob.vue index e311128..74269db 100644 --- a/frontend/nuxt-fe/components/alertJob.vue +++ b/frontend/nuxt-fe/components/alertJob.vue @@ -42,7 +42,7 @@ export default { }, mounted() { - setTimeout(this.hideAlert, 6000, this.pkey); + setTimeout(this.hideAlert, 3000, this.pkey); }, }; diff --git a/frontend/nuxt-fe/nuxt.config.js b/frontend/nuxt-fe/nuxt.config.js index b240440..3b4a36b 100644 --- a/frontend/nuxt-fe/nuxt.config.js +++ b/frontend/nuxt-fe/nuxt.config.js @@ -2,6 +2,7 @@ export default { target: 'server', + // Global page headers (https://go.nuxtjs.dev/config-head) head: { title: 'LIX Builder', @@ -40,6 +41,7 @@ export default { ] }, + diff --git a/frontend/nuxt-fe/pages/index.vue b/frontend/nuxt-fe/pages/index.vue index 9d31e61..f982075 100644 --- a/frontend/nuxt-fe/pages/index.vue +++ b/frontend/nuxt-fe/pages/index.vue @@ -36,22 +36,31 @@ export default { return {}; }, mounted() { - this.ws_success = new WebSocket('ws://localhost:5555/api/task/events/task-succeeded/') // take form env variable - this.ws_failure = new WebSocket('ws://localhost:5555/api/task/events/task-failed/') // take form env variable + + this.ws_success = new WebSocket('ws://localhost:3333/tasks') + console.log('connected to WS') this.ws_success.onmessage = function(event){ var data = JSON.parse(event.data) - var taskID = data.uuid + var taskID = data.taskID + var status = data.data.status var tList = this.$store.state.taskList + var index = this.findTask(tList, taskID) - this.$store.dispatch('updateTask', index) + var payload = { + index: index, + status: status + } + + + this.$store.dispatch('updateTask', payload) }.bind(this) - + }, async created() { diff --git a/frontend/nuxt-fe/store/index.js b/frontend/nuxt-fe/store/index.js index 06e3081..ecc6988 100644 --- a/frontend/nuxt-fe/store/index.js +++ b/frontend/nuxt-fe/store/index.js @@ -47,7 +47,18 @@ export const mutations = { this._vm.$set(state.tasksAlerts, state.tasksAlerts.length, payload) }, updateTask(state,payload){ - state.taskList[payload].status = "done" + let status = payload.status + let index = payload.index + + if (status == "SUCCESS"){ + state.taskList[index].status = "done" + } + else if (status == "FAILURE"){ + state.taskList[index].status = "failed" + } + else if (status == "RETRY"){ + state.taskList[index].status = "retry" + } }, deleteTaskAlert(state, payload) { state.tasksAlerts.splice(payload, 1); diff --git a/mongo-startup/initiate_replica.sh b/mongo-startup/initiate_replica.sh new file mode 100755 index 0000000..796fc31 --- /dev/null +++ b/mongo-startup/initiate_replica.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +echo "Starting replica set initialize" +until mongo --host mongodb1 --eval "print(\"waited for connection\")" +do + sleep 2 +done +echo "Connection finished" +echo "Creating replica set" +mongo --host mongodb1 < 0: + # mongo_db_found = True + # print("DB availaible now!") + + + # time.sleep(5) + # if not mongo_db_found: + # print("DB not there yet...") + + main() \ No newline at end of file diff --git a/v1.docker-compose.yml b/v1.docker-compose.yml new file mode 100644 index 0000000..6c53699 --- /dev/null +++ b/v1.docker-compose.yml @@ -0,0 +1,161 @@ +version: "3" + +services: + nuxt: + build: ./frontend/nuxt-fe + restart: on-failure + container_name: nuxt-app + restart: always + ports: + - "3000:3000" + depends_on: + - apihub + - mongodb1 + - mongodb2 + volumes: + - ./frontend/nuxt-fe:/app + command: npm run dev + networks: + - mongonetwork + + nginx: + build: ./nginx/ + networks: + - mongonetwork + container_name: nginx + ports: + - "80:80" + volumes: + - ./nginx/default.conf:/etc/nginx/conf.d/default.conf + depends_on: + - nuxt + - mongodb1 + - mongodb2 + + celery: + container_name: celery + build: ./celery/ + volumes: + - ./celery/server.py:/celery/server.py + - ./celery/worker.py:/celery/worker.py + environment: + MONGODB: mongodb://mongodb2 + RABBITMQ: pyamqp://rabbitmq + networks: + - mongonetwork + depends_on: + - mongodb1 + - mongodb2 + - rabbitmq + + mongo-stream: + container_name: mongo-stream + restart: on-failure + build: ./mongo-stream/ + command: python3 -u server.py + environment: + MONGODB: mongodb://mongodb2 + ports: + - "3333:3333" + depends_on: + - mongo-startup + volumes: + - ./mongo-stream/server.py:/usr/app/server.py + networks: + - mongonetwork + + mongodb1: + image: mongo:latest + container_name: replica1 + networks: + - mongonetwork + ports: + - 30001:27017 + entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ] + + mongodb2: + image: mongo:latest + container_name: replica2 + volumes: + - ./db-backup/primary:/data/db + networks: + - mongonetwork + ports: + - 30002:27017 + entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0" ] + + mongo-startup: + image: mongo + container_name: startup-agent + networks: + - mongonetwork + depends_on: + - mongodb1 + - mongodb2 + + volumes: + - ./mongo-startup:/mongo-startup + entrypoint: + - /mongo-startup/initiate_replica.sh + + apihub: + build: ./backend/ + container_name: apihub + restart: on-failure + environment: + MONGODB: mongodb://mongodb1 + RABBITMQ: pyamqp://rabbitmq + volumes: + - type: bind + source: ./backend/api.py + target: /usr/app/api.py + - type: bind + source: ./backend/req.txt + target: /usr/app/req.txt + - type: bind + source: ./backend/main.py + target: /usr/app/main.py + - type: bind + source: ./backend/core.py + target: /usr/app/core.py + - type: bind + source: ./backend/server.py + target: /usr/app/server.py + - type: bind + source: ./backend/master.pptx + target: /usr/app/master.pptx + + command: uvicorn --host=0.0.0.0 --port=8000 api:app --reload + ports: + - "8000:8000" + depends_on: + - mongodb1 + - mongo-startup + - rabbitmq + networks: + - mongonetwork + + rabbitmq: + container_name: rabbitmq + networks: + - mongonetwork + image: rabbitmq:3.8-management + ports: + - "15672:15672" + + flower: + container_name: flower + image: mher/flower:0.9.5 + command: ["flower", "--broker=amqp://rabbitmq", "--port=5555"] + networks: + - mongonetwork + ports: + - "5555:5555" + depends_on: + - mongodb1 + - mongodb2 + - rabbitmq + - celery + +networks: + mongonetwork: \ No newline at end of file From cbc1381c21aa7a3601d0972124eea1a7dd353a38 Mon Sep 17 00:00:00 2001 From: Vince Date: Sat, 19 Dec 2020 20:58:15 +0100 Subject: [PATCH 06/74] docker cheatsheet --- dockercommands.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 dockercommands.txt diff --git a/dockercommands.txt b/dockercommands.txt new file mode 100644 index 0000000..c317b72 --- /dev/null +++ b/dockercommands.txt @@ -0,0 +1,5 @@ +# Delete all containers # +docker rm -f $(docker ps -a -q) + +# Delete all images +docker system prune -a \ No newline at end of file From bc7fdf141db093b82f1ee5d66ade77979c419af5 Mon Sep 17 00:00:00 2001 From: Vince Date: Sat, 19 Dec 2020 20:58:34 +0100 Subject: [PATCH 07/74] more stable build --- mongo-startup/initiate_replica.sh | 25 +++---------------------- v1.docker-compose.yml | 2 ++ 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/mongo-startup/initiate_replica.sh b/mongo-startup/initiate_replica.sh index 796fc31..2cdc77e 100755 --- a/mongo-startup/initiate_replica.sh +++ b/mongo-startup/initiate_replica.sh @@ -1,7 +1,7 @@ #!/bin/bash echo "Starting replica set initialize" -until mongo --host mongodb1 --eval "print(\"waited for connection\")" +until mongo --host mongodb1 --eval "print(\"waited for connection\")" && mongo --host mongodb2 --eval "print(\"waited for connection 2\")" do sleep 2 done @@ -18,27 +18,8 @@ rs.initiate( ] } ) -EOF -sleep 7 -# setting mongodb2 as PRIMARY -mongo --host mongodb1 < Date: Sat, 19 Dec 2020 22:01:17 +0100 Subject: [PATCH 08/74] bug fix: no update data available --- mongo-stream/server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mongo-stream/server.py b/mongo-stream/server.py index ab6beac..6a683f1 100644 --- a/mongo-stream/server.py +++ b/mongo-stream/server.py @@ -36,8 +36,8 @@ def on_change(cls, change): message = { 'operation':change['operationType'], 'data':change['fullDocument'], - 'taskID': change['documentKey']['_id'], - 'updated':change['updateDescription'] + 'taskID': change['documentKey']['_id'] + } # message = f"{change['operationType']}: {change['fullDocument']}" From 84ef043b3cf04ab326dc3245bfe9bbeffcaab4d7 Mon Sep 17 00:00:00 2001 From: Vince Date: Sat, 19 Dec 2020 22:01:50 +0100 Subject: [PATCH 09/74] persist taskList to localStorage for smoother UX --- frontend/nuxt-fe/components/AppHeader.vue | 4 +++ frontend/nuxt-fe/components/DownloadItem.vue | 16 ++++++++--- frontend/nuxt-fe/pages/index.vue | 1 + frontend/nuxt-fe/store/index.js | 28 +++++++++++++++----- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/frontend/nuxt-fe/components/AppHeader.vue b/frontend/nuxt-fe/components/AppHeader.vue index 1b01dc3..b8d31f1 100644 --- a/frontend/nuxt-fe/components/AppHeader.vue +++ b/frontend/nuxt-fe/components/AppHeader.vue @@ -149,6 +149,10 @@ export default { watch: { $route(to, from) { this.$store.commit("changeCurrentRoute", to.name); + + if (to.name == "downloads"){ + this.$store.dispatch("clearAlertList"); + } }, }, }; diff --git a/frontend/nuxt-fe/components/DownloadItem.vue b/frontend/nuxt-fe/components/DownloadItem.vue index ad09721..205c6a6 100644 --- a/frontend/nuxt-fe/components/DownloadItem.vue +++ b/frontend/nuxt-fe/components/DownloadItem.vue @@ -48,7 +48,7 @@ viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5 cursor-pointer update" - @click="sort(0)" + @click="sort(1)" > diff --git a/frontend/nuxt-fe/pages/index.vue b/frontend/nuxt-fe/pages/index.vue index f982075..0c95fa7 100644 --- a/frontend/nuxt-fe/pages/index.vue +++ b/frontend/nuxt-fe/pages/index.vue @@ -35,6 +35,7 @@ export default { data() { return {}; }, + mounted() { this.ws_success = new WebSocket('ws://localhost:3333/tasks') diff --git a/frontend/nuxt-fe/store/index.js b/frontend/nuxt-fe/store/index.js index ecc6988..04c8916 100644 --- a/frontend/nuxt-fe/store/index.js +++ b/frontend/nuxt-fe/store/index.js @@ -12,6 +12,13 @@ export const state = () => ({ }) export const mutations = { + initialiseStore(state){ + console.log(localStorage.getItem('taskList')) + if (localStorage.getItem('taskList')){ + state.taskList = JSON.parse(localStorage.getItem('taskList')) + } + + }, updateList(state, payload) { state.list = payload }, @@ -63,6 +70,13 @@ export const mutations = { deleteTaskAlert(state, payload) { state.tasksAlerts.splice(payload, 1); }, + clearAlertList(state){ + this.state.tasksAlerts = [] + }, + updateLocalStorage(state){ + let taskList = state.taskList + localStorage.setItem('taskList',JSON.stringify(taskList)) + }, addTask(state, payload) { var date = new Date() @@ -104,34 +118,34 @@ export const actions = { }, updateTask({commit}, payload){ commit('updateTask', payload) + commit('updateLocalStorage'); }, deleteListItem({ commit }, payload) { commit('deleteListItem', payload); }, + + clearAlertList({commit}){ + commit('clearAlertList'); + + }, async sendTask({ commit }) { let onBoardingDeck = JSON.stringify({ "sections": this.state.userChoice }) commit('changeDownloadCount'); - - - var config = { - - headers: { 'Content-Type': 'application/json', - }, }; - const send = await this.$axios.$post('/v1/pptxjob', onBoardingDeck, config) .then((res) => { commit('changeDownloadStatus'); commit('addTaskAlert', res.taskID); commit('addTask', res) + commit('updateLocalStorage'); }); From e2dd6c8c5fa4e9727d73c6c87998d00b9bea3fd5 Mon Sep 17 00:00:00 2001 From: Vince Date: Sun, 20 Dec 2020 00:36:32 +0100 Subject: [PATCH 10/74] enable file sharing between api hub and celery wor --- backend/Dockerfile | 3 ++- backend/api.py | 28 +++++++++++++++++++++++++--- celery/worker.py | 18 ++++++++++++------ frontend/nuxt-fe/pages/index.vue | 3 ++- frontend/nuxt-fe/store/index.js | 2 +- mongo-startup/initiate_replica.sh | 8 ++++++-- mongo-stream/server.py | 1 + v1.docker-compose.yml | 9 +++++++-- 8 files changed, 56 insertions(+), 16 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index fbd141e..3588bf5 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -2,10 +2,11 @@ FROM python:3.8.1 WORKDIR /usr/app + COPY req.txt ./ COPY api.py core.py main.py master.pptx req.txt server.py ./ -# RUN mkdir output +RUN mkdir output RUN pip install --upgrade pip RUN pip install -r req.txt --no-cache-dir diff --git a/backend/api.py b/backend/api.py index bbc057f..dc5b359 100644 --- a/backend/api.py +++ b/backend/api.py @@ -9,11 +9,16 @@ from pptx import Presentation from server import celery import json +import uuid from datetime import datetime +from pymongo import MongoClient file_path = "master.pptx" pres= Presentation(file_path) +MONGODB= os.getenv("MONGODB") +client=MongoClient(MONGODB) +db = client["taskdb"]["ta"] tags_metadata= [ { @@ -46,6 +51,9 @@ class PPTX(BaseModel): sections: List[str] + +class Download(BaseModel): + taskID: str @app.get("/v1/sections", tags = ["powerpoint"]) @@ -63,23 +71,37 @@ async def provide_sections(): async def deliver_pptx(pptx: PPTX): task_name = "pptx" sections = pptx.sections + custom_id = str(uuid.uuid4().hex) kwargs ={ 'sections':sections, + 'customID': custom_id } - - task = celery.send_task(task_name, kwargs = kwargs, serializer='json') package = { - 'taskID': task.id, + 'taskID': custom_id, 'sections': sections } return JSONResponse(package) +@app.post("/v1/download", tags = ["job management"]) +async def download_pptx(download: Download): + + task_id = download.taskID + + + result = db.find_one({"kwargs.customID": task_id},{'result':1, '_id': 0}) + unpack = result["result"] + unpack = json.loads(unpack) + file_path = unpack["filePath"] + + + return file_path + # return FileResponse(file_path) diff --git a/celery/worker.py b/celery/worker.py index 919d241..0726d34 100644 --- a/celery/worker.py +++ b/celery/worker.py @@ -5,30 +5,36 @@ from time import sleep from celery.exceptions import Ignore from pptx import Presentation - +from pymongo import MongoClient from pptx_handler import create_pptx import json from server import app - +MONGODB = os.getenv("MONGODB") +client = MongoClient(MONGODB) +db = client["taskdb"]["ta"] @app.task(name='pptx', bind=True, max_retries=3) -def generate_pptx(self, sections): +def generate_pptx(self, sections, customID): try: pptx_path = "master.pptx" task_id=self.request.id - - pres= Presentation(pptx_path) file_path=create_pptx(pres,sections) + + except Exception as exec: self.retry(exec=exec, countdown = 2 ** self.request.retries) + output = { + 'filePath':file_path + } - return f"{task_id} finished. stored {file_path}" + + return output diff --git a/frontend/nuxt-fe/pages/index.vue b/frontend/nuxt-fe/pages/index.vue index 0c95fa7..3f37108 100644 --- a/frontend/nuxt-fe/pages/index.vue +++ b/frontend/nuxt-fe/pages/index.vue @@ -43,7 +43,8 @@ export default { this.ws_success.onmessage = function(event){ var data = JSON.parse(event.data) - var taskID = data.taskID + + var taskID = data.data.kwargs.customID var status = data.data.status var tList = this.$store.state.taskList diff --git a/frontend/nuxt-fe/store/index.js b/frontend/nuxt-fe/store/index.js index 04c8916..bec9608 100644 --- a/frontend/nuxt-fe/store/index.js +++ b/frontend/nuxt-fe/store/index.js @@ -13,7 +13,7 @@ export const state = () => ({ export const mutations = { initialiseStore(state){ - console.log(localStorage.getItem('taskList')) + if (localStorage.getItem('taskList')){ state.taskList = JSON.parse(localStorage.getItem('taskList')) } diff --git a/mongo-startup/initiate_replica.sh b/mongo-startup/initiate_replica.sh index 2cdc77e..74a6424 100755 --- a/mongo-startup/initiate_replica.sh +++ b/mongo-startup/initiate_replica.sh @@ -18,8 +18,12 @@ rs.initiate( ] } ) - +EOF +echo "replicas created" +sleep 10 +echo "setting mongodb2 as primary ..." +mongo --host mongodb1 < Date: Sun, 20 Dec 2020 01:28:52 +0100 Subject: [PATCH 11/74] added api call for serving pptx --- backend/api.py | 4 ++-- frontend/nuxt-fe/components/DownloadItem.vue | 9 ++++++- frontend/nuxt-fe/store/index.js | 25 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/backend/api.py b/backend/api.py index dc5b359..e9f9418 100644 --- a/backend/api.py +++ b/backend/api.py @@ -101,7 +101,7 @@ async def download_pptx(download: Download): - return file_path - # return FileResponse(file_path) + # return file_path + return FileResponse(file_path) diff --git a/frontend/nuxt-fe/components/DownloadItem.vue b/frontend/nuxt-fe/components/DownloadItem.vue index 205c6a6..c3a3370 100644 --- a/frontend/nuxt-fe/components/DownloadItem.vue +++ b/frontend/nuxt-fe/components/DownloadItem.vue @@ -149,8 +149,11 @@ - Download @@ -177,6 +180,10 @@ export default { table.order.listener("#update", id); }, + getDownload: function(taskID){ + // console.log(taskID) + this.$store.dispatch("downloadPresentation",taskID) + } }, created() { if(process.browser){ diff --git a/frontend/nuxt-fe/store/index.js b/frontend/nuxt-fe/store/index.js index bec9608..97c59be 100644 --- a/frontend/nuxt-fe/store/index.js +++ b/frontend/nuxt-fe/store/index.js @@ -150,5 +150,30 @@ export const actions = { }); + }, + + async downloadPresentation({commit},task){ + let taskID = JSON.stringify({ "taskID": task }) + + var config = { + headers: { + 'Content-Type': 'application/json', + 'Accept':'application/vnd.openxmlformats-officedocument.presentationml.presentation' + }, + }; + + const send = await this.$axios.$post('/v1/download',taskID,config) + .then((res) => { + + const url = window.URL.createObjectURL(new Blob([res])); + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', 'Onboarding.pptx'); //or any other extension + document.body.appendChild(link); + link.click(); + link.remove(); + + }) + } } \ No newline at end of file From 97f8c34cbf71e6bfd7042d9674ad923f652a1d7f Mon Sep 17 00:00:00 2001 From: Vince Date: Sun, 20 Dec 2020 01:29:05 +0100 Subject: [PATCH 12/74] optimized build --- v1.docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v1.docker-compose.yml b/v1.docker-compose.yml index fb3ea81..6c65ba5 100644 --- a/v1.docker-compose.yml +++ b/v1.docker-compose.yml @@ -109,7 +109,7 @@ services: MONGODB: mongodb://mongodb2 RABBITMQ: pyamqp://rabbitmq volumes: - - pptxdecks:/usr/app + - pptxdecks:/usr/app/output - type: bind source: ./backend/api.py target: /usr/app/api.py From 764445efe8ffcfabd42bce3d18b3ed97747ad045 Mon Sep 17 00:00:00 2001 From: Vince Date: Sun, 20 Dec 2020 21:52:15 +0100 Subject: [PATCH 13/74] renamed alert to more succicent naming --- frontend/nuxt-fe/components/alertJob.vue | 51 ------------------------ 1 file changed, 51 deletions(-) delete mode 100644 frontend/nuxt-fe/components/alertJob.vue diff --git a/frontend/nuxt-fe/components/alertJob.vue b/frontend/nuxt-fe/components/alertJob.vue deleted file mode 100644 index 74269db..0000000 --- a/frontend/nuxt-fe/components/alertJob.vue +++ /dev/null @@ -1,51 +0,0 @@ - - - - - \ No newline at end of file From 5b9606def5056bae7423a97c7c678b850fc41fe1 Mon Sep 17 00:00:00 2001 From: Vince Date: Sun, 20 Dec 2020 21:52:24 +0100 Subject: [PATCH 14/74] minor bug --- mongo-stream/server.py | 45 +++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/mongo-stream/server.py b/mongo-stream/server.py index f14a66c..b6055cb 100644 --- a/mongo-stream/server.py +++ b/mongo-stream/server.py @@ -32,18 +32,17 @@ def send_updates(cls, message): @classmethod def on_change(cls, change): - message = { - 'operation':change['operationType'], - 'data':change['fullDocument'], + 'operation': change['operationType'], + 'data': change['fullDocument'], 'taskID': change['documentKey']['_id'] - + } - + # message = f"{change['operationType']}: {change['fullDocument']}" # message = f"{change['operationType']}" - + ChangesHandler.send_updates(message) @@ -81,29 +80,21 @@ def main(): if __name__ == "__main__": print("started mongo watcher.") - # mongo_db_found = False - client = MongoClient(MONGODB) - tasks=client["taskdb"] - col = tasks["ta"] - print('created tasksdb and ta collection') + mongo_isLive = False - # while not mongo_db_found: - # names = client.list_database_names() + while not mongo_isLive: + try: + client = MongoClient(MONGODB) + tasks = client["taskdb"] + col = tasks["ta"] + mongo_isLive = True - # if 'taskdb' in names: - # collections=client["taskdb"].list_collection_names() - # if 'ta' in collections: - # col = client["taskdb"]["ta"] - # count_docs = int(col.count_documents({})) - - # if count_docs > 0: - # mongo_db_found = True - # print("DB availaible now!") + except Exception as e: + print('error ', e) + time.sleep(5) + + print('MongoDB connected to Websocket!') - # time.sleep(5) - # if not mongo_db_found: - # print("DB not there yet...") - - main() \ No newline at end of file + main() From 6640ad7d59552b0e4fca200543aa81667f1a5c9d Mon Sep 17 00:00:00 2001 From: Vince Date: Sun, 20 Dec 2020 21:52:39 +0100 Subject: [PATCH 15/74] change title to knowlix --- frontend/nuxt-fe/nuxt.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/nuxt-fe/nuxt.config.js b/frontend/nuxt-fe/nuxt.config.js index 3b4a36b..8055e2f 100644 --- a/frontend/nuxt-fe/nuxt.config.js +++ b/frontend/nuxt-fe/nuxt.config.js @@ -5,7 +5,7 @@ export default { // Global page headers (https://go.nuxtjs.dev/config-head) head: { - title: 'LIX Builder', + title: 'knowlix', meta: [ { charset: 'utf-8' }, { name: 'viewport', content: 'width=device-width, initial-scale=1' }, From f2a9c8d2415902a3383cc2c48dfea99016c74df0 Mon Sep 17 00:00:00 2001 From: Vince Date: Sun, 20 Dec 2020 21:53:44 +0100 Subject: [PATCH 16/74] plausibilty checks before launching expensive job --- backend/api.py | 103 ++++++++++++++++++++++++++++++++----------------- celery/core.py | 100 ++++++++++++++++++++++++----------------------- 2 files changed, 118 insertions(+), 85 deletions(-) diff --git a/backend/api.py b/backend/api.py index e9f9418..277b270 100644 --- a/backend/api.py +++ b/backend/api.py @@ -15,31 +15,30 @@ file_path = "master.pptx" -pres= Presentation(file_path) -MONGODB= os.getenv("MONGODB") -client=MongoClient(MONGODB) +pres = Presentation(file_path) +MONGODB = os.getenv("MONGODB") +client = MongoClient(MONGODB) db = client["taskdb"]["ta"] -tags_metadata= [ +tags_metadata = [ { - "name": "powerpoint", - "description": "handling powerpoint" + "name": "powerpoint", + "description": "handling powerpoint" }, { - "name": "job management", - "description": "managing celery tasks" + "name": "job management", + "description": "managing celery tasks" }, - + ] app = FastAPI( - title= "SurfBoard", - description= "API Hub for the LeanIX Onboarding Deck", - version= "1.0.0", + title="Knowlix", + description="API Hub for the LeanIX Onboarding Deck", + version="1.0.0", openapi_tags=tags_metadata) - app.add_middleware( CORSMiddleware, allow_origins=["*"], @@ -49,59 +48,91 @@ expose_headers=[] ) + class PPTX(BaseModel): sections: List[str] + class Download(BaseModel): taskID: str - - -@app.get("/v1/sections", tags = ["powerpoint"]) + + +@app.get("/v1/sections", tags=["powerpoint"]) async def provide_sections(): sections = get_sections(pres) - if (not sections) or (len(sections)==0): - raise HTTPException(status_code=404, detail="No Sections in Master pptx") + if (not sections) or (len(sections) == 0): + raise HTTPException( + status_code=404, detail="No Sections in Master pptx") - return JSONResponse(sections,status_code=200) + return JSONResponse(sections, status_code=200) -@app.post("/v1/pptxjob", tags = ["job management"]) +@app.post("/v1/pptxjob", tags=["job management"]) async def deliver_pptx(pptx: PPTX): task_name = "pptx" sections = pptx.sections + no_sections=len(sections) + sections_available = True + exists_already = False + status=None custom_id = str(uuid.uuid4().hex) - kwargs ={ - 'sections':sections, + kwargs = { + 'sections': sections, 'customID': custom_id - - } + + } + + if no_sections != 0: + exists_already = check_existence(sections, db) + else: + sections_available = False + + if not exists_already and sections_available: + task = celery.send_task(task_name, kwargs=kwargs, serializer='json') + + + if sections_available and not exists_already: + status = "success" + + elif not sections_available: + status = "no_sections" - task = celery.send_task(task_name, kwargs = kwargs, serializer='json') + elif exists_already: + status = "pptx_exists" package = { 'taskID': custom_id, - 'sections': sections + 'sections': sections, + 'status': status } - return JSONResponse(package) - -@app.post("/v1/download", tags = ["job management"]) + + +def check_existence(sections, db): + exists_already = False + no_sections = len(sections) + query = {"kwargs.sections": {"$size": no_sections, "$all": sections}} + + hits = db.count_documents(query) + + if hits > 0: + exists_already = True + + return exists_already + + +@app.post("/v1/download", tags=["powerpoint"]) async def download_pptx(download: Download): task_id = download.taskID - - result = db.find_one({"kwargs.customID": task_id},{'result':1, '_id': 0}) + result = db.find_one({"kwargs.customID": task_id}, {'result': 1, '_id': 0}) unpack = result["result"] unpack = json.loads(unpack) file_path = unpack["filePath"] - - # return file_path - return FileResponse(file_path) - - + return FileResponse(file_path) diff --git a/celery/core.py b/celery/core.py index 92af411..771b72b 100644 --- a/celery/core.py +++ b/celery/core.py @@ -2,87 +2,89 @@ import uuid import lxml.etree as etree + def extract_slide_mapping(slidelist): - """this method will get the mapping between a slide_id and rID""" + """this method will get the mapping between a slide_id and rID. This is necessary to maintain the xml syntax valid + after injection / modification""" + + slide_mapping = dict() - slide_mapping=dict() - for slide in slidelist: - rid=slide.attrib['{http://schemas.openxmlformats.org/officeDocument/2006/relationships}id'] - slide_id=slide.attrib['id'] - slide_mapping[slide_id]=rid - + rid = slide.attrib['{http://schemas.openxmlformats.org/officeDocument/2006/relationships}id'] + slide_id = slide.attrib['id'] + slide_mapping[slide_id] = rid + return slide_mapping -def prepare_sections(keys, presentation, mapping,all_sections=False): + +def prepare_sections(keys, presentation, mapping, all_sections=False): """this method will prepare a xml tree based on the passed section names the user wants to have in the pptx""" - nmap=presentation.slides._sldIdLst.nsmap - - all_sections=compile_sections(presentation,mapping) - root=etree.Element('{http://schemas.openxmlformats.org/presentationml/2006/main}sldIdLst', nsmap=nmap) - - #TODO: create toggle for - if (all_sections) and (len(keys)!=0): + nmap = presentation.slides._sldIdLst.nsmap + + all_sections = compile_sections(presentation, mapping) + root = etree.Element( + '{http://schemas.openxmlformats.org/presentationml/2006/main}sldIdLst', nsmap=nmap) + + # TODO: create toggle for + if (all_sections) and (len(keys) != 0): for key in keys: - section=all_sections[key] + section = all_sections[key] for slide in section: - etree.SubElement(root, '{http://schemas.openxmlformats.org/presentationml/2006/main}sldId',attrib=slide,nsmap=nmap) - - + etree.SubElement( + root, '{http://schemas.openxmlformats.org/presentationml/2006/main}sldId', attrib=slide, nsmap=nmap) + return root + def compile_sections(presentation, mapping): """this method will get all the sections that are in the pptx""" - - ns='{http://schemas.openxmlformats.org/officeDocument/2006/relationships}id' - xml=etree.fromstring(presentation.part.blob) - nsmap = {'p14':'http://schemas.microsoft.com/office/powerpoint/2010/main'} + + ns = '{http://schemas.openxmlformats.org/officeDocument/2006/relationships}id' + xml = etree.fromstring(presentation.part.blob) + nsmap = {'p14': 'http://schemas.microsoft.com/office/powerpoint/2010/main'} sections = xml.xpath('.//p14:sectionLst', namespaces=nsmap)[0] - - collector=dict() - pairs_col=list() - + collector = dict() + pairs_col = list() + for section in sections: - key=section.attrib['name'] + key = section.attrib['name'] for slidelist in section: for slide in slidelist: - pairs=dict() - slide_id=slide.attrib['id'] + pairs = dict() + slide_id = slide.attrib['id'] + # lookup in slide mapping to get rID + rID = mapping[slide_id] - #lookup in slide mapping to get rID - rID=mapping[slide_id] - - pairs['id']=slide_id - pairs[ns]=rID + pairs['id'] = slide_id + pairs[ns] = rID pairs_col.append(pairs) + collector[key] = pairs_col + pairs_col = list() - collector[key]=pairs_col - pairs_col=list() - return collector - -def replace_slides(new_xml,presentation,folder, save=False): + + +def replace_slides(new_xml, presentation, folder, save=False): """This method will take a xml tree and create the final pptx out of it""" - uid=str(uuid.uuid4().hex)[:10] - file_path= f"{folder}/{uid}.pptx" - slidelist=presentation.slides._sldIdLst + uid = str(uuid.uuid4().hex)[:10] + file_path = f"{folder}/{uid}.pptx" + slidelist = presentation.slides._sldIdLst + + slidelist.getparent().replace(slidelist, new_xml) - - slidelist.getparent().replace(slidelist,new_xml) - if save: presentation.save(file_path) - + return file_path -def print_xml(xml): - print(etree.tostring(xml, pretty_print=True, encoding="unicode")) \ No newline at end of file +def _print_xml(xml): + print(etree.tostring(xml, pretty_print=True, encoding="unicode")) From 60ac89321123d97cb6ffcb47ac4bc5d7aa019653 Mon Sep 17 00:00:00 2001 From: Vince Date: Sun, 20 Dec 2020 21:54:10 +0100 Subject: [PATCH 17/74] notifications for rejections by APIHub --- frontend/nuxt-fe/components/AppHeader.vue | 2 + frontend/nuxt-fe/components/alert.vue | 98 +++++++++++++++++++++++ frontend/nuxt-fe/pages/index.vue | 16 ++-- frontend/nuxt-fe/store/index.js | 82 +++++++++++-------- 4 files changed, 159 insertions(+), 39 deletions(-) create mode 100644 frontend/nuxt-fe/components/alert.vue diff --git a/frontend/nuxt-fe/components/AppHeader.vue b/frontend/nuxt-fe/components/AppHeader.vue index b8d31f1..a623d7d 100644 --- a/frontend/nuxt-fe/components/AppHeader.vue +++ b/frontend/nuxt-fe/components/AppHeader.vue @@ -138,6 +138,8 @@ export default { }, methods: { + + downloadPptx() { this.$store.commit("changeDownloadStatus"); this.$store.dispatch("sendTask"); diff --git a/frontend/nuxt-fe/components/alert.vue b/frontend/nuxt-fe/components/alert.vue new file mode 100644 index 0000000..2d0a498 --- /dev/null +++ b/frontend/nuxt-fe/components/alert.vue @@ -0,0 +1,98 @@ + + + + + \ No newline at end of file diff --git a/frontend/nuxt-fe/pages/index.vue b/frontend/nuxt-fe/pages/index.vue index 3f37108..a102e1b 100644 --- a/frontend/nuxt-fe/pages/index.vue +++ b/frontend/nuxt-fe/pages/index.vue @@ -1,11 +1,12 @@ \ No newline at end of file diff --git a/frontend/nuxt-fe/middleware/auth.js b/frontend/nuxt-fe/middleware/auth.js index db39c30..c5b159b 100644 --- a/frontend/nuxt-fe/middleware/auth.js +++ b/frontend/nuxt-fe/middleware/auth.js @@ -1,7 +1,7 @@ export default function ({ store, redirect }) { if (!store.state.auth.loggedIn) { - + console.log("hit auth") return redirect('/login') } } \ No newline at end of file diff --git a/frontend/nuxt-fe/middleware/dropdown-helper.js b/frontend/nuxt-fe/middleware/dropdown-helper.js new file mode 100644 index 0000000..b369e21 --- /dev/null +++ b/frontend/nuxt-fe/middleware/dropdown-helper.js @@ -0,0 +1,9 @@ +export default ({ isServer }) => { + // Don't use the middleware on server-side + if (isServer) return + // Return a promise to tell nuxt.js to wait for the end of it + return new Promise((resolve) => { + // Wait 1 second between each route + setTimeout(resolve, 1); + }) +} \ No newline at end of file diff --git a/frontend/nuxt-fe/middleware/guest.js b/frontend/nuxt-fe/middleware/guest.js index 663f1c7..302c006 100644 --- a/frontend/nuxt-fe/middleware/guest.js +++ b/frontend/nuxt-fe/middleware/guest.js @@ -1,6 +1,6 @@ export default function ({ store, redirect }) { if (store.state.auth.loggedIn) { - + console.log("hit guest") return redirect('/') } } \ No newline at end of file diff --git a/frontend/nuxt-fe/middleware/onboarding.js b/frontend/nuxt-fe/middleware/onboarding.js new file mode 100644 index 0000000..5bbbe06 --- /dev/null +++ b/frontend/nuxt-fe/middleware/onboarding.js @@ -0,0 +1,5 @@ +export default function ({ store, redirect }) { + + return redirect('/') + + } \ No newline at end of file diff --git a/frontend/nuxt-fe/nuxt.config.js b/frontend/nuxt-fe/nuxt.config.js index d24057c..b44c2e7 100644 --- a/frontend/nuxt-fe/nuxt.config.js +++ b/frontend/nuxt-fe/nuxt.config.js @@ -88,7 +88,7 @@ export default { }, router: { - middleware: ['auth'] + middleware:['dropdown-helper'] }, diff --git a/frontend/nuxt-fe/pages/index.vue b/frontend/nuxt-fe/pages/index.vue index cd71ed1..a8a79cc 100644 --- a/frontend/nuxt-fe/pages/index.vue +++ b/frontend/nuxt-fe/pages/index.vue @@ -11,6 +11,7 @@ export default { components: { landingpage, }, + middleware: 'auth', computed: {}, methods: {}, diff --git a/frontend/nuxt-fe/pages/login-new.vue b/frontend/nuxt-fe/pages/login-new.vue new file mode 100644 index 0000000..0d181a7 --- /dev/null +++ b/frontend/nuxt-fe/pages/login-new.vue @@ -0,0 +1,134 @@ + + + + + \ No newline at end of file diff --git a/frontend/nuxt-fe/pages/logout.vue b/frontend/nuxt-fe/pages/logout.vue index 19474d1..f4add4f 100644 --- a/frontend/nuxt-fe/pages/logout.vue +++ b/frontend/nuxt-fe/pages/logout.vue @@ -167,7 +167,7 @@ export default { name: "logout", - middleware: '', + middleware: 'guest', data() { return { login: { diff --git a/frontend/nuxt-fe/pages/onboarding/downloads.vue b/frontend/nuxt-fe/pages/onboarding/downloads.vue index 360bfd0..972460a 100644 --- a/frontend/nuxt-fe/pages/onboarding/downloads.vue +++ b/frontend/nuxt-fe/pages/onboarding/downloads.vue @@ -24,6 +24,7 @@ export default { components: { DownloadItem, }, + middleware: 'auth', }; diff --git a/frontend/nuxt-fe/pages/onboarding/index.vue b/frontend/nuxt-fe/pages/onboarding/index.vue new file mode 100644 index 0000000..1bae7d6 --- /dev/null +++ b/frontend/nuxt-fe/pages/onboarding/index.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/frontend/nuxt-fe/pages/onboarding/modular.vue b/frontend/nuxt-fe/pages/onboarding/modular.vue index 8745547..f1d3363 100644 --- a/frontend/nuxt-fe/pages/onboarding/modular.vue +++ b/frontend/nuxt-fe/pages/onboarding/modular.vue @@ -127,6 +127,7 @@ export default { Section, alert, }, + middleware: 'auth', methods: { downloadPptx() { this.$store.commit("changeDownloadStatus"); diff --git a/frontend/nuxt-fe/store/auth.js b/frontend/nuxt-fe/store/auth.js index 9f0bf1c..6a2bb53 100644 --- a/frontend/nuxt-fe/store/auth.js +++ b/frontend/nuxt-fe/store/auth.js @@ -37,12 +37,13 @@ export const mutations = { // clear our the state, essentially logging out the user [AUTH_MUTATIONS.LOGOUT](state) { - state.id = '' - state.user = '' + state.id = null + state.user = null state.loggedIn = false - state.access_token = '' - state.tokenExpires = '' - state.userID = '' + state.access_token = null + state.tokenExpires = null + state.userID = null + localStorage.setItem('taskList', null) }, @@ -109,6 +110,7 @@ export const actions = { logUserOut({ commit, state }) { console.log("logout triggered...") commit(AUTH_MUTATIONS.LOGOUT) + this.$router.push("/login") }, From b3caba81c93e4e39d97056e7e64209a01072d2f9 Mon Sep 17 00:00:00 2001 From: Vince Date: Wed, 6 Jan 2021 21:09:51 +0100 Subject: [PATCH 72/74] new animation of login --- frontend/nuxt-fe/components/AppHeader.vue | 4 + frontend/nuxt-fe/pages/archive/login.vue | 208 +++++++++++++++ frontend/nuxt-fe/pages/login-new.vue | 134 ---------- frontend/nuxt-fe/pages/login.vue | 294 ++++++++++------------ 4 files changed, 342 insertions(+), 298 deletions(-) create mode 100644 frontend/nuxt-fe/pages/archive/login.vue delete mode 100644 frontend/nuxt-fe/pages/login-new.vue diff --git a/frontend/nuxt-fe/components/AppHeader.vue b/frontend/nuxt-fe/components/AppHeader.vue index 938cc0e..de8728c 100644 --- a/frontend/nuxt-fe/components/AppHeader.vue +++ b/frontend/nuxt-fe/components/AppHeader.vue @@ -262,5 +262,9 @@ fontLIX { animation: fadeIn; animation-duration: 0.3s ; } +.solutions-leave-active{ + animation: fadeOut; + animation-duration: 0.5s ; +} \ No newline at end of file diff --git a/frontend/nuxt-fe/pages/archive/login.vue b/frontend/nuxt-fe/pages/archive/login.vue new file mode 100644 index 0000000..77981de --- /dev/null +++ b/frontend/nuxt-fe/pages/archive/login.vue @@ -0,0 +1,208 @@ + + + + + \ No newline at end of file diff --git a/frontend/nuxt-fe/pages/login-new.vue b/frontend/nuxt-fe/pages/login-new.vue deleted file mode 100644 index 0d181a7..0000000 --- a/frontend/nuxt-fe/pages/login-new.vue +++ /dev/null @@ -1,134 +0,0 @@ - - - - - \ No newline at end of file diff --git a/frontend/nuxt-fe/pages/login.vue b/frontend/nuxt-fe/pages/login.vue index 77981de..8ade321 100644 --- a/frontend/nuxt-fe/pages/login.vue +++ b/frontend/nuxt-fe/pages/login.vue @@ -1,161 +1,131 @@ \ No newline at end of file From f709ec1ec5ecedd325fb0479f481af374d25a3fd Mon Sep 17 00:00:00 2001 From: Vince Date: Wed, 6 Jan 2021 21:32:42 +0100 Subject: [PATCH 73/74] error handling login --- frontend/nuxt-fe/pages/login.vue | 4 +-- frontend/nuxt-fe/plugins/auth-axios.js | 37 ++++++++++++++------------ frontend/nuxt-fe/store/auth.js | 37 ++++++++++++++------------ 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/frontend/nuxt-fe/pages/login.vue b/frontend/nuxt-fe/pages/login.vue index 8ade321..4e7d7db 100644 --- a/frontend/nuxt-fe/pages/login.vue +++ b/frontend/nuxt-fe/pages/login.vue @@ -1,6 +1,6 @@