From 08feaa5343cf1a0a412c8e7826b9d2ad3dcab1dc Mon Sep 17 00:00:00 2001 From: Quentin France Date: Fri, 29 Apr 2022 10:00:19 +0200 Subject: [PATCH] Save commands history --- package-lock.json | 70 +++- package.json | 1 + src/main/webapp/app/common/domain/Service.ts | 22 +- .../webapp/app/common/primary/HistoryStore.ts | 24 ++ .../secondary/ProjectHistoryRepository.ts | 6 +- .../app/common/secondary/RestServiceId.ts | 44 +- src/main/webapp/app/main.ts | 24 +- .../domain/client/AngularService.ts | 1 - .../AngularGenerator.component.ts | 16 +- .../angular-generator/AngularGenerator.vue | 14 - .../springboot/secondary/ProjectRepository.ts | 35 +- .../secondary/SpringBootRepository.ts | 109 ++--- .../secondary/client/AngularRepository.ts | 13 +- .../secondary/client/ReactRepository.ts | 13 +- .../secondary/client/VueRepository.ts | 15 +- .../spec/common/domain/History.fixture.ts | 7 + .../domain/ProjectHistoryService.fixture.ts | 2 +- .../common/primary/HistoryStore.fixture.ts | 12 + .../spec/common/primary/HistoryStore.spec.ts | 35 ++ .../ProjectHistoryRepository.spec.ts | 11 +- .../common/secondary/RestHistory.fixture.ts | 2 +- .../common/secondary/RestServiceId.spec.ts | 22 +- .../AngularGenerator.spec.ts | 35 -- .../secondary/ProjectRepository.spec.ts | 87 ++-- .../secondary/SpringBootRepository.spec.ts | 377 +++++++++++------- .../client/AngularRepository.spec.ts | 28 +- .../secondary/client/ReactRepository.spec.ts | 25 +- .../secondary/client/VueRepository.spec.ts | 25 +- 28 files changed, 673 insertions(+), 402 deletions(-) create mode 100644 src/main/webapp/app/common/primary/HistoryStore.ts create mode 100644 src/test/javascript/spec/common/domain/History.fixture.ts create mode 100644 src/test/javascript/spec/common/primary/HistoryStore.fixture.ts create mode 100644 src/test/javascript/spec/common/primary/HistoryStore.spec.ts diff --git a/package-lock.json b/package-lock.json index 1cb9ce072c9..8614bd893a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "vue-router": "4.0.14" }, "devDependencies": { + "@pinia/testing": "0.0.11", "@prettier/plugin-xml": "2.1.0", "@rushstack/eslint-patch": "1.1.3", "@types/jest": "27.4.1", @@ -1426,10 +1427,25 @@ "node": ">= 8" } }, + "node_modules/@pinia/testing": { + "version": "0.0.11", + "resolved": "https://registry.npmjs.org/@pinia/testing/-/testing-0.0.11.tgz", + "integrity": "sha512-iJxUHV0Uj1jS7zvN5oVtSZ2BRI4PlG1xbqPkMeJasPtbqsnoxBmkwputDzqX5Dd1I1z9gEfyYOeE2duK3xGWpQ==", + "dev": true, + "dependencies": { + "vue-demi": "*" + }, + "funding": { + "url": "https://github.com/sponsors/posva" + }, + "peerDependencies": { + "pinia": ">=2.0.13" + } + }, "node_modules/@popperjs/core": { - "version": "2.11.4", - "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.4.tgz", - "integrity": "sha512-q/ytXxO5NKvyT37pmisQAItCFqA7FD/vNb8dgaJy3/630Fsc+Mz9/9f2SziBoIZ30TJooXyTwZmhi1zjXmObYg==", + "version": "2.11.5", + "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.5.tgz", + "integrity": "sha512-9X2obfABZuDVLCgPK9aX0a/x4jaOEweTTWE2+9sr0Qqqevj2Uv5XorvusThmc9XGYpS9yI+fhh8RTafBtGposw==", "peer": true, "funding": { "type": "opencollective", @@ -12115,6 +12131,32 @@ "@vue/shared": "3.2.33" } }, + "node_modules/vue-demi": { + "version": "0.12.5", + "resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.12.5.tgz", + "integrity": "sha512-BREuTgTYlUr0zw0EZn3hnhC3I6gPWv+Kwh4MCih6QcAeaTlaIX0DwOVN0wHej7hSvDPecz4jygy/idsgKfW58Q==", + "dev": true, + "hasInstallScript": true, + "bin": { + "vue-demi-fix": "bin/vue-demi-fix.js", + "vue-demi-switch": "bin/vue-demi-switch.js" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + }, + "peerDependencies": { + "@vue/composition-api": "^1.0.0-rc.1", + "vue": "^3.0.0-0 || ^2.6.0" + }, + "peerDependenciesMeta": { + "@vue/composition-api": { + "optional": true + } + } + }, "node_modules/vue-eslint-parser": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-8.2.0.tgz", @@ -13616,10 +13658,19 @@ "fastq": "^1.6.0" } }, + "@pinia/testing": { + "version": "0.0.11", + "resolved": "https://registry.npmjs.org/@pinia/testing/-/testing-0.0.11.tgz", + "integrity": "sha512-iJxUHV0Uj1jS7zvN5oVtSZ2BRI4PlG1xbqPkMeJasPtbqsnoxBmkwputDzqX5Dd1I1z9gEfyYOeE2duK3xGWpQ==", + "dev": true, + "requires": { + "vue-demi": "*" + } + }, "@popperjs/core": { - "version": "2.11.4", - "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.4.tgz", - "integrity": "sha512-q/ytXxO5NKvyT37pmisQAItCFqA7FD/vNb8dgaJy3/630Fsc+Mz9/9f2SziBoIZ30TJooXyTwZmhi1zjXmObYg==", + "version": "2.11.5", + "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.5.tgz", + "integrity": "sha512-9X2obfABZuDVLCgPK9aX0a/x4jaOEweTTWE2+9sr0Qqqevj2Uv5XorvusThmc9XGYpS9yI+fhh8RTafBtGposw==", "peer": true }, "@prettier/plugin-xml": { @@ -21603,6 +21654,13 @@ "@vue/shared": "3.2.33" } }, + "vue-demi": { + "version": "0.12.5", + "resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.12.5.tgz", + "integrity": "sha512-BREuTgTYlUr0zw0EZn3hnhC3I6gPWv+Kwh4MCih6QcAeaTlaIX0DwOVN0wHej7hSvDPecz4jygy/idsgKfW58Q==", + "dev": true, + "requires": {} + }, "vue-eslint-parser": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-8.2.0.tgz", diff --git a/package.json b/package.json index 1b6cd1c73fb..8712edb1dc6 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "vue-router": "4.0.14" }, "devDependencies": { + "@pinia/testing": "0.0.11", "@prettier/plugin-xml": "2.1.0", "@rushstack/eslint-patch": "1.1.3", "@types/jest": "27.4.1", diff --git a/src/main/webapp/app/common/domain/Service.ts b/src/main/webapp/app/common/domain/Service.ts index 755f5fe20e9..9a2407843b5 100644 --- a/src/main/webapp/app/common/domain/Service.ts +++ b/src/main/webapp/app/common/domain/Service.ts @@ -1,12 +1,28 @@ export enum Service { + AOP_LOGGING = 'AOP_LOGGING', + ANGULAR = 'ANGULAR', + DOWNLOAD = 'DOWNLOAD', + FRONTEND_MAVEN_PLUGIN = 'FRONTEND_MAVEN_PLUGIN', INITIALIZATION = 'INITIALIZATION', - MAVEN = 'MAVEN', + JACOCO_CHECK_MINIMAL_COVERAGE = 'JACOCO_CHECK_MINIMAL_COVERAGE', JAVA_BASE = 'JAVA_BASE', + LOGSTASH = 'LOGSTASH', + MAVEN_JAVA = 'MAVEN_JAVA', + MARIADB = 'MARIADB', + MYSQL = 'MYSQL', + MONGODB = 'MONGODB', + POSTGRESQL = 'POSTGRESQL', + SONAR_JAVA_BACKEND = 'SONAR_JAVA_BACKEND', + SONAR_JAVA_BACKEND_AND_FRONTEND = 'SONAR_JAVA_BACKEND_AND_FRONTEND', SPRINGBOOT = 'SPRINGBOOT', + SPRINGBOOT_ACTUATOR = 'SPRINGBOOT_ACTUATOR', + SPRINGBOOT_JWT = 'SPRINGBOOT_JWT', + SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION = 'SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION', SPRINGBOOT_MVC_WITH_TOMCAT = 'SPRINGBOOT_MVC_WITH_TOMCAT', - ANGULAR = 'ANGULAR', + SPRINGBOOT_WEBFLUX_NETTY = 'SPRINGBOOT_WEBFLUX_NETTY', REACT = 'REACT', + REACT_STYLED = 'REACT_STYLED', VUE = 'VUE', - FRONTEND_MAVEN_PLUGIN = 'FRONTEND_MAVEN_PLUGIN', + VUE_STYLED = 'VUE_STYLED', UNKNOWN = 'UNKNOWN', } diff --git a/src/main/webapp/app/common/primary/HistoryStore.ts b/src/main/webapp/app/common/primary/HistoryStore.ts new file mode 100644 index 00000000000..8d8780bc737 --- /dev/null +++ b/src/main/webapp/app/common/primary/HistoryStore.ts @@ -0,0 +1,24 @@ +import { defineStore } from 'pinia'; +import { History } from '@/common/domain/History'; + +const emptyHistory = (): History => ({ + services: [], +}); + +export const useHistoryStore = defineStore('HistoryStore', { + state: () => { + return { + history: emptyHistory(), + }; + }, + + getters: { + getHistory: state => state.history, + }, + + actions: { + async setHistory(history: History) { + this.history = history; + }, + }, +}); diff --git a/src/main/webapp/app/common/secondary/ProjectHistoryRepository.ts b/src/main/webapp/app/common/secondary/ProjectHistoryRepository.ts index fe1013ae06b..60bfe64cdb7 100644 --- a/src/main/webapp/app/common/secondary/ProjectHistoryRepository.ts +++ b/src/main/webapp/app/common/secondary/ProjectHistoryRepository.ts @@ -5,9 +5,11 @@ import { ProjectHistoryService } from '@/common/domain/ProjectHistoryService'; import { AxiosHttp } from '@/http/AxiosHttp'; export default class ProjectHistoryRepository implements ProjectHistoryService { - constructor(private axiosHttp: AxiosHttp) {} + constructor(private axiosHttp: AxiosHttp, private historyStore: any) {} async get(folder: Folder): Promise { - return this.axiosHttp.get('api/project-histories', { params: { folder } }).then(response => toHistory(response.data)); + return this.axiosHttp + .get('api/project-histories', { params: { folder } }) + .then(response => this.historyStore.setHistory(toHistory(response.data))); } } diff --git a/src/main/webapp/app/common/secondary/RestServiceId.ts b/src/main/webapp/app/common/secondary/RestServiceId.ts index fd8496944fb..3b982f4c518 100644 --- a/src/main/webapp/app/common/secondary/RestServiceId.ts +++ b/src/main/webapp/app/common/secondary/RestServiceId.ts @@ -4,24 +4,56 @@ export type RestServiceId = string; export const toService = (restServiceId: RestServiceId): Service => { switch (restServiceId) { + case 'aop-logging': + return Service.AOP_LOGGING; + case 'angular': + return Service.ANGULAR; + case 'download': + return Service.DOWNLOAD; + case 'frontend-maven-plugin': + return Service.FRONTEND_MAVEN_PLUGIN; case 'init': return Service.INITIALIZATION; - case 'maven': - return Service.MAVEN; + case 'jacoco-check-min-coverage': + return Service.JACOCO_CHECK_MINIMAL_COVERAGE; case 'java-base': return Service.JAVA_BASE; + case 'logstash': + return Service.LOGSTASH; + case 'mariadb': + return Service.MARIADB; + case 'maven-java': + return Service.MAVEN_JAVA; + case 'mongodb': + return Service.MONGODB; + case 'mysql': + return Service.MYSQL; + case 'postgresql': + return Service.POSTGRESQL; + case 'sonar-java-backend': + return Service.SONAR_JAVA_BACKEND; + case 'sonar-java-backend-and-frontend': + return Service.SONAR_JAVA_BACKEND_AND_FRONTEND; case 'springboot': return Service.SPRINGBOOT; + case 'springboot-jwt': + return Service.SPRINGBOOT_JWT; + case 'springboot-jwt-basic-auth': + return Service.SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION; + case 'springboot-actuator': + return Service.SPRINGBOOT_ACTUATOR; case 'springboot-tomcat': return Service.SPRINGBOOT_MVC_WITH_TOMCAT; - case 'angular': - return Service.ANGULAR; + case 'springboot-webflux-netty': + return Service.SPRINGBOOT_WEBFLUX_NETTY; case 'react': return Service.REACT; + case 'react-styled': + return Service.REACT_STYLED; case 'vue': return Service.VUE; - case 'frontend-maven-plugin': - return Service.FRONTEND_MAVEN_PLUGIN; + case 'vue-styled': + return Service.VUE_STYLED; default: return Service.UNKNOWN; } diff --git a/src/main/webapp/app/main.ts b/src/main/webapp/app/main.ts index c92cdfef5d6..68c2958171a 100644 --- a/src/main/webapp/app/main.ts +++ b/src/main/webapp/app/main.ts @@ -8,8 +8,10 @@ import AngularRepository from '@/springboot/secondary/client/AngularRepository'; import ReactRepository from '@/springboot/secondary/client/ReactRepository'; import VueRepository from '@/springboot/secondary/client/VueRepository'; import SpringBootRepository from './springboot/secondary/SpringBootRepository'; +import ProjectHistoryRepository from '@/common/secondary/ProjectHistoryRepository'; import ConsoleLogger from '@/common/secondary/ConsoleLogger'; import { FileDownloader } from '@/common/primary/FileDownloader'; +import { useHistoryStore } from '@/common/primary/HistoryStore'; import { createPinia } from 'pinia'; import piniaPersist from 'pinia-plugin-persist'; @@ -18,26 +20,30 @@ import 'bootstrap-icons/font/bootstrap-icons.css'; import 'bootstrap'; import '../content/css/custom.css'; +const app = createApp(App); +const pinia = createPinia(); +pinia.use(piniaPersist); +app.use(pinia); + const axiosHttp = new AxiosHttp(axios.create({ baseURL: '' })); const fileDownloader = new FileDownloader(window); const consoleLogger = new ConsoleLogger(console); -const projectRepository = new ProjectRepository(axiosHttp); -const angularRepository = new AngularRepository(axiosHttp); -const reactRepository = new ReactRepository(axiosHttp); -const vueRepository = new VueRepository(axiosHttp); -const springBootRepository = new SpringBootRepository(axiosHttp); +const historyStore = useHistoryStore(); +const projectHistoryRepository = new ProjectHistoryRepository(axiosHttp, historyStore); +const projectRepository = new ProjectRepository(axiosHttp, projectHistoryRepository); +const angularRepository = new AngularRepository(axiosHttp, projectHistoryRepository); +const reactRepository = new ReactRepository(axiosHttp, projectHistoryRepository); +const vueRepository = new VueRepository(axiosHttp, projectHistoryRepository); +const springBootRepository = new SpringBootRepository(axiosHttp, projectHistoryRepository); -const app = createApp(App); -const pinia = createPinia(); -pinia.use(piniaPersist); app.provide('angularService', angularRepository); app.provide('fileDownloader', fileDownloader); +app.provide('historyStore', historyStore); app.provide('logger', consoleLogger); app.provide('projectService', projectRepository); app.provide('reactService', reactRepository); app.provide('springBootService', springBootRepository); app.provide('vueService', vueRepository); app.use(router); -app.use(pinia); app.mount('#app'); diff --git a/src/main/webapp/app/springboot/domain/client/AngularService.ts b/src/main/webapp/app/springboot/domain/client/AngularService.ts index 5e059ed64a0..2b5912f1de5 100644 --- a/src/main/webapp/app/springboot/domain/client/AngularService.ts +++ b/src/main/webapp/app/springboot/domain/client/AngularService.ts @@ -2,5 +2,4 @@ import { Project } from '@/springboot/domain/Project'; export interface AngularService { add(project: Project): Promise; - addWithStyle(project: Project): Promise; } diff --git a/src/main/webapp/app/springboot/primary/angular-generator/AngularGenerator.component.ts b/src/main/webapp/app/springboot/primary/angular-generator/AngularGenerator.component.ts index 3180852f5a1..e81f8da3244 100644 --- a/src/main/webapp/app/springboot/primary/angular-generator/AngularGenerator.component.ts +++ b/src/main/webapp/app/springboot/primary/angular-generator/AngularGenerator.component.ts @@ -1,4 +1,4 @@ -import { defineComponent, inject, ref } from 'vue'; +import { defineComponent, inject } from 'vue'; import { AngularService } from '@/springboot/domain/client/AngularService'; import { ProjectToUpdate, toProject } from '@/springboot/primary/ProjectToUpdate'; import { Logger } from '@/common/domain/Logger'; @@ -23,25 +23,17 @@ export default defineComponent({ const angularService = inject('angularService') as AngularService; const selectorPrefix = 'angular-generator'; - const isAngularWithStyle = ref(false); const addAngular = async (): Promise => { if (props.project.folder !== '') { - if (isAngularWithStyle.value) { - await angularService - .addWithStyle(toProject(props.project as ProjectToUpdate)) - .catch(error => logger.error('Adding Angular with style to project failed', error)); - } else { - await angularService - .add(toProject(props.project as ProjectToUpdate)) - .catch(error => logger.error('Adding Angular to project failed', error)); - } + await angularService + .add(toProject(props.project as ProjectToUpdate)) + .catch(error => logger.error('Adding Angular to project failed', error)); } }; return { selectorPrefix, - isAngularWithStyle, addAngular, props, }; diff --git a/src/main/webapp/app/springboot/primary/angular-generator/AngularGenerator.vue b/src/main/webapp/app/springboot/primary/angular-generator/AngularGenerator.vue index d88b7bbe137..7e1300d49b7 100644 --- a/src/main/webapp/app/springboot/primary/angular-generator/AngularGenerator.vue +++ b/src/main/webapp/app/springboot/primary/angular-generator/AngularGenerator.vue @@ -1,19 +1,5 @@