From 291c38dbdd8a0388918f201803c08e31bcfb077c Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 4 Mar 2021 16:32:01 +0900 Subject: [PATCH 1/5] Add stats model --- frontend/models/statistics.ts | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 frontend/models/statistics.ts diff --git a/frontend/models/statistics.ts b/frontend/models/statistics.ts new file mode 100644 index 00000000..cf3d0f38 --- /dev/null +++ b/frontend/models/statistics.ts @@ -0,0 +1,59 @@ +export type Label = {[key: string]: number} + +export type User = {[key: string]: number} + +export class Statistics { + constructor( + public label: Label, + public userLabel: User, + public total: number, + public remaining: number, + public user: User + ) {} + + static valueOf( + { label, user_label, total, remaining, user }: + { + label: Label, + user_label: User, + total: number, + remaining: number, + user: User + } + ): Statistics { + return new Statistics(label, user_label, total, remaining, user) + } + + private makeData(object: Label | User, label: string) { + const labels = object ? Object.keys(object) : [] + const counts = object ? Object.values(object) : [] + return { + labels, + datasets: [{ + label, + backgroundColor: '#00d1b2', + data: counts + }] + } + } + + public labelStats(label: string) { + return this.makeData(this.label, label) + } + + public userStats(label: string) { + return this.makeData(this.user, label) + } + + public progress(labels: string[]) { + const complete = this.total - this.remaining + const incomplete = this.remaining + return { + datasets: [{ + data: [complete, incomplete], + backgroundColor: ['#00d1b2', '#ffdd57'] + }], + labels + } + } +} From e697b76235583ef122267d19c6db68a738d7b47a Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 4 Mar 2021 16:32:21 +0900 Subject: [PATCH 2/5] Add stats repository --- frontend/repositories/statistics/api.ts | 15 +++++++++++++++ frontend/repositories/statistics/interface.ts | 6 ++++++ 2 files changed, 21 insertions(+) create mode 100644 frontend/repositories/statistics/api.ts create mode 100644 frontend/repositories/statistics/interface.ts diff --git a/frontend/repositories/statistics/api.ts b/frontend/repositories/statistics/api.ts new file mode 100644 index 00000000..a8b6c8b2 --- /dev/null +++ b/frontend/repositories/statistics/api.ts @@ -0,0 +1,15 @@ +import ApiService from '@/services/api.service' +import { Statistics } from '@/models/statistics' +import { StatisticsRepository } from './interface' + +export class FromApiStatisticsRepository implements StatisticsRepository { + constructor( + private readonly request = ApiService + ) {} + + async fetch(projectId: string): Promise { + const url = `/projects/${projectId}/statistics` + const response = await this.request.get(url) + return Statistics.valueOf(response.data) + } +} diff --git a/frontend/repositories/statistics/interface.ts b/frontend/repositories/statistics/interface.ts new file mode 100644 index 00000000..eb067808 --- /dev/null +++ b/frontend/repositories/statistics/interface.ts @@ -0,0 +1,6 @@ +import { Statistics } from '@/models/statistics' + +export interface StatisticsRepository { + + fetch(projectId: string): Promise +} From c65718bff88c0f5761da266b61b05340049e7c99 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 4 Mar 2021 16:32:35 +0900 Subject: [PATCH 3/5] Add stats service --- .../application/statistics.service.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 frontend/services/application/statistics.service.ts diff --git a/frontend/services/application/statistics.service.ts b/frontend/services/application/statistics.service.ts new file mode 100644 index 00000000..47b8029e --- /dev/null +++ b/frontend/services/application/statistics.service.ts @@ -0,0 +1,27 @@ +import { Statistics } from '@/models/statistics' +import { StatisticsRepository } from '@/repositories/statistics/interface' + +export class StatisticsDTO { + label: object + user: object + progress: object + + constructor(item: Statistics, labelText: string, userText: string, progressLabels: string[]) { + this.label = item.labelStats(labelText) + this.user = item.userStats(userText) + this.progress = item.progress(progressLabels) + } +} + +export class StatisticsApplicationService { + constructor( + private readonly repository: StatisticsRepository + ) {} + + public async fetchStatistics( + projectId: string, labelText: string, userText: string, progressLabels: string[] + ): Promise { + const item = await this.repository.fetch(projectId) + return new StatisticsDTO(item, labelText, userText, progressLabels) + } +} From bd7d5d41b31e622a82ee9cd4edd154bb57a486be Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 4 Mar 2021 16:32:49 +0900 Subject: [PATCH 4/5] Add stats service to the plugin --- frontend/plugins/services.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/plugins/services.ts b/frontend/plugins/services.ts index 37d20061..4e2730b6 100644 --- a/frontend/plugins/services.ts +++ b/frontend/plugins/services.ts @@ -5,12 +5,14 @@ import { FromApiUserItemListRepository } from '@/repositories/user/api' import { FromApiRoleItemListRepository } from '@/repositories/role/api' import { FromApiProjectItemListRepository } from '@/repositories/project/api' import { FromApiCommentItemListRepository } from '@/repositories/comment/api' +import { FromApiStatisticsRepository } from '@/repositories/statistics/api' import { LabelApplicationService } from '@/services/application/label.service' import { MemberApplicationService } from '@/services/application/member.service' import { UserApplicationService } from '@/services/application/user.service' import { RoleApplicationService } from '@/services/application/role.service' import { ProjectApplicationService } from '@/services/application/project.service' import { CommentApplicationService } from '@/services/application/comment.service' +import { StatisticsApplicationService } from '@/services/application/statistics.service' export interface Services { label: LabelApplicationService, @@ -18,7 +20,8 @@ export interface Services { user: UserApplicationService, role: RoleApplicationService, project: ProjectApplicationService, - comment: CommentApplicationService + comment: CommentApplicationService, + statistics: StatisticsApplicationService } declare module 'vue/types/vue' { @@ -40,13 +43,16 @@ const plugin: Plugin = (context, inject) => { const project = new ProjectApplicationService(projectRepository) const commentRepository = new FromApiCommentItemListRepository() const comment = new CommentApplicationService(commentRepository) + const statisticsRepository = new FromApiStatisticsRepository() + const statistics = new StatisticsApplicationService(statisticsRepository) const services: Services = { label, member, user, role, project, - comment + comment, + statistics } inject('services', services) } From 1b9469897eeee53d4b8d5132cc0d838d162e08b2 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 4 Mar 2021 16:33:07 +0900 Subject: [PATCH 5/5] Remove vuex from stats page --- .../pages/projects/_id/statistics/index.vue | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/frontend/pages/projects/_id/statistics/index.vue b/frontend/pages/projects/_id/statistics/index.vue index 57f494b7..b3f7f618 100644 --- a/frontend/pages/projects/_id/statistics/index.vue +++ b/frontend/pages/projects/_id/statistics/index.vue @@ -1,12 +1,12 @@