diff --git a/src/main/webapp/app/shared/gitlab/gitlab-path-selector/gitlab-path-selector.component.html b/src/main/webapp/app/shared/gitlab/gitlab-path-selector/gitlab-path-selector.component.html new file mode 100644 index 0000000000000000000000000000000000000000..a941deda8a7ac89382313431dd3faae865799819 --- /dev/null +++ b/src/main/webapp/app/shared/gitlab/gitlab-path-selector/gitlab-path-selector.component.html @@ -0,0 +1,53 @@ +<div> + <div class="modal-header"> + <h4 class="modal-title" jhiTranslate="gitlab.pathSelector.title">Gitlab Path</h4> + <button type="button" class="close" data-dismiss="modal" aria-hidden="true" (click)="closeModal(undefined)">×</button> + </div> + <div class="modal-body"> + <div class="justify-content-center p-1"> + <jhi-alert></jhi-alert> + <jhi-alert-error></jhi-alert-error> + <div class="table-responsive p-1"> + <table class="table table-striped"> + <thead> + <tr> + <th></th> + <th><span jhiTranslate="gitlab.pathSelector.name">Name</span></th> + <th><span jhiTranslate="gitlab.pathSelector.description">Description</span></th> + <th><span jhiTranslate="gitlab.pathSelector.visibility">Visibility</span></th> + <th><span jhiTranslate="gitlab.pathSelector.url">URL</span></th> + </tr> + </thead> + <tbody> + <tr *ngFor="let group of groups"> + <td> + <img + [height]="48" + src="{{ group.avatarUrl ? group.avatarUrl : '' }}"/> + <!--onerror="this.src='/content/images/image-placeholder.png'" + />--> + </td> + <td> + <strong>{{group.name}}</strong> + </td> + <td> + <span>{{group.description}}</span> + </td> + <td> + <span>{{group.visibility}}</span> + </td> + <td> + <span>{{group.webUrl}}</span> + </td> + <td> + <button type="button" class="btn ml-2 btn-primary" (click)="closeModal(group)" jhiTranslate="gitlab.pathSelector.select"> + Select + </button> + </td> + </tr> + </tbody> + </table> + </div> + </div> + </div> +</div> diff --git a/src/main/webapp/app/shared/gitlab/gitlab-path-selector/gitlab-path-selector.component.scss b/src/main/webapp/app/shared/gitlab/gitlab-path-selector/gitlab-path-selector.component.scss new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/main/webapp/app/shared/gitlab/gitlab-path-selector/gitlab-path-selector.component.ts b/src/main/webapp/app/shared/gitlab/gitlab-path-selector/gitlab-path-selector.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..824a4bbf1d6d7961037dba0ad779967aa0ecfb87 --- /dev/null +++ b/src/main/webapp/app/shared/gitlab/gitlab-path-selector/gitlab-path-selector.component.ts @@ -0,0 +1,49 @@ +import { Component, OnInit } from '@angular/core'; +import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; +import { JhiAlertService } from 'ng-jhipster'; +import { GitlabGroup } from 'app/shared/model/gitlab-group.model'; +import { GitlabService } from 'app/shared/gitlab/gitlab.service'; + +@Component({ + selector: 'jhi-gitlab-path-selector', + templateUrl: './gitlab-path-selector.component.html', + styleUrls: ['./gitlab-path-selector.component.scss'], +}) +export class GitlabPathSelectorComponent implements OnInit { + groups: GitlabGroup[] | undefined; + subgroups: GitlabGroup[] | undefined; + + constructor(private activeModal: NgbActiveModal, private jhiAlertService: JhiAlertService, private gitlabService: GitlabService) {} + + ngOnInit(): void { + this.gitlabService.getGroups().subscribe( + data => { + this.groups = data; + }, + error => { + this.jhiAlertService.error(error.error); + } + ); + } + + /** + * Utility function used to retrieve the upper groups in the + * hierarchy + */ + getParentGroups() { + return this.groups?.filter(group => !group.parentId); + } + + /** + * Utility function used to retrieve the subgroups of + * a given group + * @param group to search for subGroups + */ + getSubGroupsOfGroup(group: GitlabGroup) { + return this.groups?.filter(subGroup => subGroup.parentId === group.id); + } + + closeModal(group: GitlabGroup | undefined) { + this.activeModal.close(group); + } +} diff --git a/src/main/webapp/app/shared/gitlab/gitlab.module.ts b/src/main/webapp/app/shared/gitlab/gitlab.module.ts new file mode 100644 index 0000000000000000000000000000000000000000..76b2eaaf7fe53837ef94942d0efb5afa5e3fd104 --- /dev/null +++ b/src/main/webapp/app/shared/gitlab/gitlab.module.ts @@ -0,0 +1,10 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { GitlabPathSelectorComponent } from './gitlab-path-selector/gitlab-path-selector.component'; +import { GitSearchV2SharedModule } from 'app/shared/shared.module'; + +@NgModule({ + imports: [CommonModule, GitSearchV2SharedModule], + declarations: [GitlabPathSelectorComponent], +}) +export class GitlabModule {} diff --git a/src/main/webapp/app/shared/gitlab/gitlab.service.ts b/src/main/webapp/app/shared/gitlab/gitlab.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..a4ced30e3dcf944a8d46484cabb4a70fd9de6ae3 --- /dev/null +++ b/src/main/webapp/app/shared/gitlab/gitlab.service.ts @@ -0,0 +1,30 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { SERVER_API_URL } from 'app/app.constants'; +import { GitlabGroup } from 'app/shared/model/gitlab-group.model'; +import { Observable } from 'rxjs'; + +@Injectable({ + providedIn: 'root', +}) +export class GitlabService { + public resourceUrl = SERVER_API_URL + 'api/gitlab/'; + + constructor(private http: HttpClient) {} + + /** + * Used to retrieve all groups of current user + * (As user: their groups, as admin: all groups) + */ + public getGroups(): Observable<Array<GitlabGroup>> { + return this.http.get<Array<GitlabGroup>>(`${this.resourceUrl}groups`); + } + + /** + * used to retrieve subgroups of a given Gitlab group + * @param group to retrieve its subgroups + */ + public getSubGroups(group: GitlabGroup): Observable<Array<GitlabGroup>> { + return this.http.get<Array<GitlabGroup>>(`${this.resourceUrl}subgroups/${group.id}`); + } +} diff --git a/src/main/webapp/app/shared/model/gitlab-group.model.ts b/src/main/webapp/app/shared/model/gitlab-group.model.ts new file mode 100644 index 0000000000000000000000000000000000000000..a3947f3bda2f4729eba2278efd3a34284b888338 --- /dev/null +++ b/src/main/webapp/app/shared/model/gitlab-group.model.ts @@ -0,0 +1,21 @@ +export enum IVisibility { + PUBLIC = 'public', + PRIVATE = 'private', + INTERNAL = 'internal', +} + +/** + * Gitlab Group model basing on org.gitlab4j.api.models.Group + */ +export interface GitlabGroup { + id: number; + name: string; + path: string; + description: string; + visibility: IVisibility; + avatarUrl: string; + webUrl: string; + fullName: string; + fullPath: string; + parentId: number; +} diff --git a/src/main/webapp/i18n/de/gitlabModal.json b/src/main/webapp/i18n/de/gitlabModal.json new file mode 100644 index 0000000000000000000000000000000000000000..73e1fe33435875ed4b7b3b35bf9ac59d4eeabda7 --- /dev/null +++ b/src/main/webapp/i18n/de/gitlabModal.json @@ -0,0 +1,12 @@ +{ + "gitlab": { + "pathSelector": { + "title": "Gitlab Pfad", + "name": "Name", + "description": "Beschreibung", + "url": "URL", + "visibility": "Freischaltung", + "select": "Auswählen" + } + } +} diff --git a/src/main/webapp/i18n/en/gitlabModal.json b/src/main/webapp/i18n/en/gitlabModal.json new file mode 100644 index 0000000000000000000000000000000000000000..14a18e97e47c78e89d98d8b84b35c15ddc23f43a --- /dev/null +++ b/src/main/webapp/i18n/en/gitlabModal.json @@ -0,0 +1,12 @@ +{ + "gitlab": { + "pathSelector": { + "title": "Gitlab Path", + "name": "Name", + "description": "Description", + "url": "URL", + "visibility": "Visibility", + "select": "Select" + } + } +}