From 743f6da92b7c3ab5545934481c297be6ef659a6f Mon Sep 17 00:00:00 2001 From: Dominik Schenk Date: Wed, 4 Aug 2021 18:25:36 +0200 Subject: [PATCH] added group by for repos --- src/app/core/services/store/store.types.ts | 5 +++ src/app/routes/home/home.component.html | 39 +++++++++++++--------- src/app/routes/home/home.component.ts | 26 +++++++++++++-- src/app/shared/functions/group.ts | 10 ++++++ src/app/shared/functions/index.ts | 1 + src/theme/typo.scss | 8 +++++ 6 files changed, 70 insertions(+), 19 deletions(-) create mode 100644 src/app/shared/functions/group.ts diff --git a/src/app/core/services/store/store.types.ts b/src/app/core/services/store/store.types.ts index 90de9ee..271da9f 100644 --- a/src/app/core/services/store/store.types.ts +++ b/src/app/core/services/store/store.types.ts @@ -7,7 +7,12 @@ export type RepositorySetting = { }; export type RepositoriesSettings = Array; +export type RepositoriesSettingsGrouped = Array; +export type RepositoriesSettingsGroup = { + title?: string; + repositories?: RepositoriesSettings; +} export type DiffFormate = 'side-by-side' | 'line-by-line'; export type Tag = { diff --git a/src/app/routes/home/home.component.html b/src/app/routes/home/home.component.html index 1e4abff..8ad937b 100644 --- a/src/app/routes/home/home.component.html +++ b/src/app/routes/home/home.component.html @@ -1,24 +1,31 @@ -
+

{{ 'PAGES.HOME.TITLE' | translate }}

- +

Group by: + None | + Folder | + Tags +

-
-
-
Name
-
Order
-
Tags
-
-
-
{{repo.name}}
-
{{repo.path}}
-
-
- {{tag}} + +

{{group.title}}

+
+
+
Name
+
Folder
+
Tags
+
+
+
{{repo.name}}
+
{{repo.path}}
+
+
+ {{tag}} +
-
+
diff --git a/src/app/routes/home/home.component.ts b/src/app/routes/home/home.component.ts index f64246e..73015e0 100644 --- a/src/app/routes/home/home.component.ts +++ b/src/app/routes/home/home.component.ts @@ -1,15 +1,16 @@ import { filter, take } from 'rxjs/operators'; import { TemplatePortal } from '@angular/cdk/portal'; -import { RepositorySetting } from '@core/services'; +import { RepositoriesSettingsGroup, RepositoriesSettingsGrouped, RepositorySetting } from '@core/services'; import { RepositoryService } from './../repository/repository.service'; import { Component, OnInit, TemplateRef, ViewChild, ViewContainerRef } from '@angular/core'; import { Router } from '@angular/router'; import { RepositoriesSettings, RepositoriesSettingsService } from '@core/services'; import { Overlay, OverlayRef } from '@angular/cdk/overlay'; import { fromEvent, merge, Subscription } from 'rxjs'; -import { Command, open } from '@tauri-apps/api/shell'; +import { open } from '@tauri-apps/api/shell'; import { Clipboard } from '@angular/cdk/clipboard'; import { invoke } from '@tauri-apps/api/tauri'; +import { groupBy } from '@shared/functions'; @Component({ selector: 'app-home', @@ -18,7 +19,9 @@ import { invoke } from '@tauri-apps/api/tauri'; }) export class HomeComponent implements OnInit { - repositories: RepositoriesSettings = []; + private repositories: RepositoriesSettings = []; + repositoriesGrouped: RepositoriesSettingsGrouped = []; + @ViewChild('userMenu') userMenu: TemplateRef; overlayRef: OverlayRef | null; sub: Subscription; @@ -37,6 +40,7 @@ export class HomeComponent implements OnInit { this.repositoryService.unload(); this.loadRepos(); this.repositoryService.clearUIBranches(); + this.groupNone(); } loadRepos(): void { @@ -121,6 +125,21 @@ export class HomeComponent implements OnInit { } + groupFolder() { + this.repositoriesGrouped = groupBy(this.repositories, (t: any) => t.path.substring(0, t.path.lastIndexOf('/'))); + } + + groupTags() { + this.repositoriesGrouped = groupBy(this.repositories, (t: any) => t.tags[0]); + } + + groupNone() { + const group: RepositoriesSettingsGroup = { + repositories: this.repositories + } + this.repositoriesGrouped = [group]; + } + close() { this.sub && this.sub.unsubscribe(); if (this.overlayRef) { @@ -128,4 +147,5 @@ export class HomeComponent implements OnInit { this.overlayRef = null; } } + } diff --git a/src/app/shared/functions/group.ts b/src/app/shared/functions/group.ts new file mode 100644 index 0000000..b512592 --- /dev/null +++ b/src/app/shared/functions/group.ts @@ -0,0 +1,10 @@ +export function groupBy(x: any, f: Function) { + const groupedObj = x.reduce((a: any, b: any) => { + const key = f(b); + a[key] ||= []; + a[key].push(b); + return a; + }, {}); + + return Object.keys(groupedObj).map(key => ({ title: key, repositories: groupedObj[key] })); +} diff --git a/src/app/shared/functions/index.ts b/src/app/shared/functions/index.ts index cf6bddb..9892451 100644 --- a/src/app/shared/functions/index.ts +++ b/src/app/shared/functions/index.ts @@ -3,3 +3,4 @@ export * from './harmonize-path'; export * from './select-folder'; export * from './diff'; export * from './sleep'; +export * from './group'; diff --git a/src/theme/typo.scss b/src/theme/typo.scss index 1fd776a..ca19c57 100644 --- a/src/theme/typo.scss +++ b/src/theme/typo.scss @@ -6,3 +6,11 @@ .no-break { white-space: nowrap; } + +a[cds-text="link"] { + cursor: pointer; +} + +// [cds-text="subsection"] { +// margin: 10px 0 10px; +// }