Skip to content

Commit

Permalink
Merge pull request #1550 from Franceq34/indicate-when-button-already-…
Browse files Browse the repository at this point in the history
…used

Indicate when button already used
  • Loading branch information
pascalgrimaud authored May 1, 2022
2 parents aae5829 + 5cceca0 commit 1b4ebb2
Show file tree
Hide file tree
Showing 45 changed files with 1,281 additions and 852 deletions.
1 change: 1 addition & 0 deletions src/main/webapp/app/common/domain/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum Service {
MARIADB = 'MARIADB',
MYSQL = 'MYSQL',
MONGODB = 'MONGODB',
MONGOCK = 'MONGOCK',
POSTGRESQL = 'POSTGRESQL',
SONAR_JAVA_BACKEND = 'SONAR_JAVA_BACKEND',
SONAR_JAVA_BACKEND_AND_FRONTEND = 'SONAR_JAVA_BACKEND_AND_FRONTEND',
Expand Down
5 changes: 5 additions & 0 deletions src/main/webapp/app/common/primary/HistoryStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineStore } from 'pinia';
import { History } from '@/common/domain/History';
import { Service } from '@/common/domain/Service';

const emptyHistory = (): History => ({
services: [],
Expand All @@ -14,6 +15,10 @@ export const useHistoryStore = defineStore('HistoryStore', {

getters: {
getHistory: state => state.history,
hasCalledService:
state =>
(service: Service): boolean =>
state.history.services.includes(service),
},

actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default defineComponent({
type: Boolean,
default: false,
},
outlined: {
type: Boolean,
default: false,
},
icon: {
type: String,
default: undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<button class="btn btn-outline-primary" :disabled="disabled">
<button class="btn" :class="outlined ? 'btn-outline-primary' : 'btn-primary'" :disabled="disabled">
<IconVue v-if="icon" class="me-1" :name="icon" :aria-hidden="true" />
{{ label }}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class ProjectHistoryRepository implements ProjectHistoryService {
async get(folder: Folder): Promise<History> {
return this.axiosHttp
.get<RestHistory>('api/project-histories', { params: { folder } })
.then(response => this.historyStore.setHistory(toHistory(response.data)));
.then(response => this.historyStore.setHistory(toHistory(response.data)))
.catch(() => this.historyStore.setHistory({ services: [] }));
}
}
2 changes: 2 additions & 0 deletions src/main/webapp/app/common/secondary/RestServiceId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const toService = (restServiceId: RestServiceId): Service => {
return Service.MAVEN_JAVA;
case 'mongodb':
return Service.MONGODB;
case 'mongock':
return Service.MONGOCK;
case 'mysql':
return Service.MYSQL;
case 'postgresql':
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ const springBootRepository = new SpringBootRepository(axiosHttp, projectHistoryR

app.provide('angularService', angularRepository);
app.provide('fileDownloader', fileDownloader);
app.provide('globalWindow', window);
app.provide('historyStore', historyStore);
app.provide('logger', consoleLogger);
app.provide('projectService', projectRepository);
app.provide('projectHistoryService', projectHistoryRepository);
app.provide('reactService', reactRepository);
app.provide('springBootService', springBootRepository);
app.provide('vueService', vueRepository);
Expand Down
97 changes: 19 additions & 78 deletions src/main/webapp/app/springboot/primary/Generator.component.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
import { ProjectService } from '@/springboot/domain/ProjectService';
import { defineComponent, inject, ref } from 'vue';
import { ProjectToUpdate, toProject } from '@/springboot/primary/ProjectToUpdate';
import { Logger } from '@/common/domain/Logger';
import { AngularGeneratorVue } from '@/springboot/primary/angular-generator';
import { ReactGeneratorVue } from '@/springboot/primary/react-generator';
import { VueGeneratorVue } from '@/springboot/primary/vue-generator';
import { SvelteGeneratorVue } from '@/springboot/primary/svelte-generator';
import { SpringBootGeneratorVue } from '@/springboot/primary/spring-boot-generator';
import { FileDownloader } from '@/common/primary/FileDownloader';
import { ProjectToUpdate } from '@/springboot/primary/ProjectToUpdate';
import { AngularGeneratorVue } from '@/springboot/primary/generator/angular-generator';
import { ReactGeneratorVue } from '@/springboot/primary/generator/react-generator';
import { VueGeneratorVue } from '@/springboot/primary/generator/vue-generator';
import { SvelteGeneratorVue } from '@/springboot/primary/generator/svelte-generator';
import { SpringBootGeneratorVue } from '@/springboot/primary/generator/spring-boot-generator';
import { DefaultButtonVue } from '@/common/primary/default-button';
import { HeaderVue } from '@/springboot/primary/header';
import { IconVue } from '@/common/primary/icon';
import { ProjectGeneratorVue } from '@/springboot/primary/generator/project-generator';
import { ProjectHistoryService } from '@/common/domain/ProjectHistoryService';
import { History } from '@/common/domain/History';

export default defineComponent({
name: 'GeneratorComponent',
components: {
HeaderVue,
IconVue,
DefaultButtonVue,
ProjectGeneratorVue,
SpringBootGeneratorVue,
AngularGeneratorVue,
ReactGeneratorVue,
SvelteGeneratorVue,
VueGeneratorVue,
},
setup() {
const logger = inject('logger') as Logger;
const fileDownloader = inject('fileDownloader') as FileDownloader;
const projectService = inject('projectService') as ProjectService;

const projectHistoryService = inject('projectHistoryService') as ProjectHistoryService;
const globalWindow = inject('globalWindow') as Window;
const selectorPrefix = 'generator';

const project = ref<ProjectToUpdate>({
Expand All @@ -39,63 +38,11 @@ export default defineComponent({
const server = ref<string>();
const client = ref<string>();

const initProject = async (): Promise<void> => {
if (project.value.folder !== '') {
await projectService.init(toProject(project.value)).catch(error => logger.error('Project initialization failed', error.message));
}
};

const addMaven = async (): Promise<void> => {
if (project.value.folder !== '') {
await projectService.addMaven(toProject(project.value)).catch(error => logger.error('Adding Maven to project failed', error));
}
};

const addJaCoCo = async (): Promise<void> => {
if (project.value.folder !== '') {
await projectService.addJaCoCo(toProject(project.value)).catch(error => logger.error('Adding JaCoCo to project failed', error));
}
};

const addSonarBackend = async (): Promise<void> => {
if (project.value.folder !== '') {
await projectService
.addSonarBackend(toProject(project.value))
.catch(error => logger.error('Adding Sonar Backend to project failed', error));
}
};

const addSonarBackendFrontend = async (): Promise<void> => {
if (project.value.folder !== '') {
await projectService
.addSonarBackendFrontend(toProject(project.value))
.catch(error => logger.error('Adding Sonar Backend+Frontend to project failed', error));
}
};

const addJavaBase = async (): Promise<void> => {
if (project.value.folder !== '') {
await projectService
.addJavaBase(toProject(project.value))
.catch(error => logger.error('Adding Java Base to project failed', error));
}
};

const addFrontendMavenPlugin = async (): Promise<void> => {
if (project.value.folder !== '') {
await projectService
.addFrontendMavenPlugin(toProject(project.value))
.catch(error => logger.error('Adding Frontend Maven Plugin to project failed', error));
}
};

const download = async (): Promise<void> => {
await projectService
.download(toProject(project.value))
.then(file => {
fileDownloader.download(file);
})
.catch(error => logger.error('Downloading project failed', error));
let timeoutId: number | undefined = undefined;
const getCurrentProjectHistory = (): Promise<History> => projectHistoryService.get(project.value.folder);
const debounceGetProjectHistory = (): void => {
if (timeoutId) globalWindow.clearTimeout(timeoutId);
timeoutId = globalWindow.setTimeout(() => getCurrentProjectHistory, 400);
};

return {
Expand All @@ -104,15 +51,9 @@ export default defineComponent({
buildTool,
server,
client,
initProject,
addMaven,
addJaCoCo,
addSonarBackend,
addSonarBackendFrontend,
addJavaBase,
addFrontendMavenPlugin,
download,
selectorPrefix,
getCurrentProjectHistory,
debounceGetProjectHistory,
};
},
});
70 changes: 10 additions & 60 deletions src/main/webapp/app/springboot/primary/Generator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
<div class="row g-3">
<div class="col-12">
<label for="path" class="form-label">Path (required) : </label>
<input id="path" v-model="project.folder" type="text" class="form-control" required autofocus />
<input
id="path"
v-model="project.folder"
type="text"
class="form-control"
required
autofocus
@input="debounceGetProjectHistory"
/>
</div>
<div class="col-12">
<label for="basename" class="form-label">Basename : </label>
Expand Down Expand Up @@ -384,65 +392,7 @@

<div class="col py-2">
<div id="v-pills-tab" class="tab-content">
<div id="v-pills-init" class="tab-pane fade show active" role="tabpanel" aria-labelledby="v-pills-home-tab">
<div class="d-flex flex-column gap-3">
<div>
<DefaultButtonVue id="init" :label="'Init'" :data-selector="selectorPrefix + '.init-button'" @click.prevent="initProject" />
</div>
<div>
<DefaultButtonVue
v-if="buildTool === 'maven'"
id="maven"
:label="'Maven'"
:data-selector="selectorPrefix + '.add-maven-button'"
@click.prevent="addMaven"
/>
<DefaultButtonVue
id="jacoco"
:label="'JaCoCo'"
:data-selector="selectorPrefix + '.add-jacoco-button'"
@click.prevent="addJaCoCo"
/>
<DefaultButtonVue
id="sonar-backend"
:label="'Sonar Backend'"
:data-selector="selectorPrefix + '.add-sonar-backend-button'"
@click.prevent="addSonarBackend"
/>
<DefaultButtonVue
id="sonar-backend-frontend"
:label="'Sonar Backend+Frontend'"
:data-selector="selectorPrefix + '.add-sonar-backend-frontend-button'"
@click.prevent="addSonarBackendFrontend"
/>
</div>
<div>
<DefaultButtonVue
id="javabase"
:label="'Java Base'"
:data-selector="selectorPrefix + '.add-java-base-button'"
@click.prevent="addJavaBase"
/>
</div>
<div>
<DefaultButtonVue
id="frontend-maven-plugin"
:label="'Frontend Maven Plugin'"
:data-selector="selectorPrefix + '.add-frontend-maven-plugin-button'"
@click.prevent="addFrontendMavenPlugin"
/>
</div>
<div>
<DefaultButtonVue
v-if="project.folder !== ''"
id="download"
:label="'Download'"
:data-selector="selectorPrefix + '.download-button'"
@click.prevent="download"
/>
</div>
</div>
</div>
<ProjectGeneratorVue :build-tool="buildTool" :project="project" />
<SpringBootGeneratorVue v-if="server === 'springboot'" :project="project" />
<AngularGeneratorVue v-if="client === 'angular'" :project="project" />
<ReactGeneratorVue v-if="client === 'react'" :project="project" />
Expand Down
Loading

0 comments on commit 1b4ebb2

Please sign in to comment.