Skip to content

Commit

Permalink
Frontend: Add GeneratorButton styled with HistoryStore
Browse files Browse the repository at this point in the history
  • Loading branch information
Franceq34 authored and Quentin France committed May 1, 2022
1 parent 01fa410 commit b4a9c5a
Show file tree
Hide file tree
Showing 39 changed files with 670 additions and 372 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
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
12 changes: 6 additions & 6 deletions src/main/webapp/app/springboot/primary/Generator.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { defineComponent, ref } from 'vue';
import { ProjectToUpdate } from '@/springboot/primary/ProjectToUpdate';
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 { 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/project-generator';
import { ProjectGeneratorVue } from '@/springboot/primary/generator/project-generator';

export default defineComponent({
name: 'GeneratorComponent',
Expand Down
148 changes: 148 additions & 0 deletions src/main/webapp/app/springboot/primary/generator/ServiceProjection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { Service } from '@/common/domain/Service';

export type ServiceProjection =
| 'aop-logging'
| 'angular'
| 'download'
| 'initialization'
| 'frontend-maven-plugin'
| 'jacoco-check-minimal-coverage'
| 'java-base'
| 'logstash'
| 'maven-java'
| 'mariadb'
| 'mysql'
| 'mongodb'
| 'mongock'
| 'postgresql'
| 'sonar-java-backend'
| 'sonar-java-backend-and-frontend'
| 'spring-boot'
| 'spring-boot-actuator'
| 'spring-boot-jwt'
| 'spring-boot-jwt-with-basic-authentication'
| 'spring-boot-mvc-with-tomcat'
| 'spring-boot-webflux-netty'
| 'react'
| 'react-styled'
| 'vue'
| 'vue-styled'
| 'unknown';

export const toServiceProjection = (service: Service): ServiceProjection => {
switch (service) {
case Service.AOP_LOGGING:
return 'aop-logging';
case Service.ANGULAR:
return 'angular';
case Service.DOWNLOAD:
return 'download';
case Service.INITIALIZATION:
return 'initialization';
case Service.FRONTEND_MAVEN_PLUGIN:
return 'frontend-maven-plugin';
case Service.JACOCO_CHECK_MINIMAL_COVERAGE:
return 'jacoco-check-minimal-coverage';
case Service.JAVA_BASE:
return 'java-base';
case Service.LOGSTASH:
return 'logstash';
case Service.MAVEN_JAVA:
return 'maven-java';
case Service.MARIADB:
return 'mariadb';
case Service.MYSQL:
return 'mysql';
case Service.MONGODB:
return 'mongodb';
case Service.MONGOCK:
return 'mongock';
case Service.POSTGRESQL:
return 'postgresql';
case Service.SONAR_JAVA_BACKEND:
return 'sonar-java-backend';
case Service.SONAR_JAVA_BACKEND_AND_FRONTEND:
return 'sonar-java-backend-and-frontend';
case Service.SPRINGBOOT:
return 'spring-boot';
case Service.SPRINGBOOT_ACTUATOR:
return 'spring-boot-actuator';
case Service.SPRINGBOOT_JWT:
return 'spring-boot-jwt';
case Service.SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION:
return 'spring-boot-jwt-with-basic-authentication';
case Service.SPRINGBOOT_MVC_WITH_TOMCAT:
return 'spring-boot-mvc-with-tomcat';
case Service.SPRINGBOOT_WEBFLUX_NETTY:
return 'spring-boot-webflux-netty';
case Service.REACT:
return 'react';
case Service.REACT_STYLED:
return 'react-styled';
case Service.VUE:
return 'vue';
case Service.VUE_STYLED:
return 'vue-styled';
case Service.UNKNOWN:
return 'unknown';
}
};

export const fromServiceProjection = (serviceProjection: ServiceProjection): Service => {
switch (serviceProjection) {
case 'aop-logging':
return Service.AOP_LOGGING;
case 'angular':
return Service.ANGULAR;
case 'download':
return Service.DOWNLOAD;
case 'initialization':
return Service.INITIALIZATION;
case 'frontend-maven-plugin':
return Service.FRONTEND_MAVEN_PLUGIN;
case 'jacoco-check-minimal-coverage':
return Service.JACOCO_CHECK_MINIMAL_COVERAGE;
case 'java-base':
return Service.JAVA_BASE;
case 'logstash':
return Service.LOGSTASH;
case 'maven-java':
return Service.MAVEN_JAVA;
case 'mariadb':
return Service.MARIADB;
case 'mysql':
return Service.MYSQL;
case 'mongodb':
return Service.MONGODB;
case 'mongock':
return Service.MONGOCK;
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 'spring-boot':
return Service.SPRINGBOOT;
case 'spring-boot-actuator':
return Service.SPRINGBOOT_ACTUATOR;
case 'spring-boot-jwt':
return Service.SPRINGBOOT_JWT;
case 'spring-boot-jwt-with-basic-authentication':
return Service.SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION;
case 'spring-boot-mvc-with-tomcat':
return Service.SPRINGBOOT_MVC_WITH_TOMCAT;
case 'spring-boot-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 'vue-styled':
return Service.VUE_STYLED;
case 'unknown':
return Service.UNKNOWN;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ 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';
import { DefaultButtonVue } from '@/common/primary/default-button';
import { GeneratorButtonVue } from '@/springboot/primary/generator/generator-button';

export default defineComponent({
name: 'AngularGeneratorComponent',

components: {
DefaultButtonVue,
GeneratorButtonVue,
},

props: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<template>
<div id="v-pills-angular" class="tab-pane fade" role="tabpanel" aria-labelledby="v-pills-settings-tab">
<DefaultButtonVue
id="angular"
:label="'Generate Angular'"
:data-selector="selectorPrefix + '.add-angular-button'"
@click.prevent="addAngular"
/>
<GeneratorButtonVue :label="'Generate Angular'" :service="'angular'" :selector-prefix="selectorPrefix" @click.prevent="addAngular" />
</div>
</template>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { computed, defineComponent, inject } from 'vue';
import { DefaultButtonVue } from '@/common/primary/default-button';
import { StoreGeneric } from 'pinia';
import { fromServiceProjection, ServiceProjection } from '@/springboot/primary/generator/ServiceProjection';

export default defineComponent({
name: 'GeneratorButtonComponent',

components: {
DefaultButtonVue,
},

props: {
label: {
type: String,
required: true,
},
service: {
type: String,
required: true,
},
selectorPrefix: {
type: String,
required: true,
},
},

setup(props) {
const historyStore = inject('historyStore') as StoreGeneric;

const hasCalledService = computed(() => historyStore.hasCalledService(fromServiceProjection(props.service as ServiceProjection)));

return {
hasCalledService,
};
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<DefaultButtonVue
:id="`generator-button-${service}`"
:label="label"
:icon="hasCalledService ? 'arrow-clockwise' : undefined"
:outlined="hasCalledService"
:data-selector="`${selectorPrefix}.add-${service}-button`"
/>
</template>

<script lang="ts" src="./GeneratorButton.component.ts"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import GeneratorButtonComponent from './GeneratorButton.component';
import GeneratorButtonVue from './GeneratorButton.vue';

export { GeneratorButtonComponent, GeneratorButtonVue };
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { defineComponent, inject } from 'vue';
import { ProjectToUpdate, toProject } from '@/springboot/primary/ProjectToUpdate';
import { Logger } from '@/common/domain/Logger';
import { DefaultButtonVue } from '@/common/primary/default-button';
import { ProjectService } from '@/springboot/domain/ProjectService';
import { FileDownloader } from '@/common/primary/FileDownloader';
import { GeneratorButtonVue } from '@/springboot/primary/generator/generator-button';

export default defineComponent({
name: 'ProjectGeneratorComponent',

components: {
DefaultButtonVue,
GeneratorButtonVue,
},

props: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<template>
<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>
<GeneratorButtonVue :label="'Init'" :service="'initialization'" :selector-prefix="selectorPrefix" @click.prevent="initProject" />
</div>
<div>
<GeneratorButtonVue
v-if="buildTool === 'maven'"
:label="'Maven'"
:service="'maven-java'"
:selector-prefix="selectorPrefix"
@click.prevent="addMaven"
/>
<GeneratorButtonVue
:label="'JaCoCo'"
:service="'jacoco-check-minimal-coverage'"
:selector-prefix="selectorPrefix"
@click.prevent="addJaCoCo"
/>
<GeneratorButtonVue
:label="'Sonar Backend'"
:service="'sonar-java-backend'"
:selector-prefix="selectorPrefix"
@click.prevent="addSonarBackend"
/>
<GeneratorButtonVue
:label="'Sonar Backend+Frontend'"
:service="'sonar-java-backend-and-frontend'"
:selector-prefix="selectorPrefix"
@click.prevent="addSonarBackendFrontend"
/>
</div>
<div>
<GeneratorButtonVue :label="'Java Base'" :service="'java-base'" :selector-prefix="selectorPrefix" @click.prevent="addJavaBase" />
</div>
<div>
<GeneratorButtonVue
:label="'Frontend Maven Plugin'"
:service="'frontend-maven-plugin'"
:selector-prefix="selectorPrefix"
@click.prevent="addFrontendMavenPlugin"
/>
</div>
<div>
<GeneratorButtonVue
v-if="project.folder !== ''"
:label="'Download'"
:service="'download'"
:selector-prefix="selectorPrefix"
@click.prevent="download"
/>
</div>
</div>
</div>
</template>

<script lang="ts" src="./ProjectGenerator.component.ts"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { defineComponent, inject, ref } from 'vue';
import { ProjectToUpdate, toProject } from '@/springboot/primary/ProjectToUpdate';
import { Logger } from '@/common/domain/Logger';
import { ReactService } from '@/springboot/domain/client/ReactService';
import { DefaultButtonVue } from '@/common/primary/default-button';
import { GeneratorButtonVue } from '@/springboot/primary/generator/generator-button';

export default defineComponent({
name: 'ReactGeneratorComponent',

components: {
DefaultButtonVue,
GeneratorButtonVue,
},

props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
</span>
</label>
</div>
<DefaultButtonVue
id="react"
<GeneratorButtonVue
:label="'Generate React'"
:data-selector="selectorPrefix + '.add-react-button'"
:service="isReactWithStyle ? 'react-styled' : 'react'"
:selector-prefix="selectorPrefix"
@click.prevent="addReact"
/>
</div>
Expand Down
Loading

0 comments on commit b4a9c5a

Please sign in to comment.