diff --git a/harbor-app/src/app/project/action-project/action-project.component.html b/harbor-app/src/app/project/action-project/action-project.component.html new file mode 100644 index 000000000..9ec7c700b --- /dev/null +++ b/harbor-app/src/app/project/action-project/action-project.component.html @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/harbor-app/src/app/project/action-project/action-project.component.ts b/harbor-app/src/app/project/action-project/action-project.component.ts new file mode 100644 index 000000000..7542d3b7e --- /dev/null +++ b/harbor-app/src/app/project/action-project/action-project.component.ts @@ -0,0 +1,30 @@ +import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { Project } from '../project'; +import { ProjectService } from '../project.service'; + +@Component({ + selector: 'action-project', + templateUrl: 'action-project.component.html' +}) +export class ActionProjectComponent { + + @Output() togglePublic = new EventEmitter(); + @Output() deleteProject = new EventEmitter(); + + @Input() project: Project; + + constructor(private projectService: ProjectService) {} + + toggle() { + if(this.project) { + this.project.public === 0 ? this.project.public = 1 : this.project.public = 0; + this.togglePublic.emit(this.project); + } + } + + delete() { + if(this.project) { + this.deleteProject.emit(this.project); + } + } +} \ No newline at end of file diff --git a/harbor-app/src/app/project/create-project/create-project.component.html b/harbor-app/src/app/project/create-project/create-project.component.html index c8e2c5c66..81e3dca69 100644 --- a/harbor-app/src/app/project/create-project/create-project.component.html +++ b/harbor-app/src/app/project/create-project/create-project.component.html @@ -27,4 +27,3 @@ - \ No newline at end of file diff --git a/harbor-app/src/app/project/create-project/create-project.component.ts b/harbor-app/src/app/project/create-project/create-project.component.ts index f9df072d5..3f66ca179 100644 --- a/harbor-app/src/app/project/create-project/create-project.component.ts +++ b/harbor-app/src/app/project/create-project/create-project.component.ts @@ -4,6 +4,7 @@ import { Response } from '@angular/http'; import { Project } from '../project'; import { ProjectService } from '../project.service'; +import { MessageService } from '../../global-message/message.service'; @Component({ selector: 'create-project', @@ -19,13 +20,13 @@ export class CreateProjectComponent { hasError: boolean; @Output() create = new EventEmitter(); - - constructor(private projectService: ProjectService) {} + + constructor(private projectService: ProjectService, private messageService: MessageService) {} onSubmit() { this.hasError = false; this.projectService - .createProject(this.project.name, this.project.public) + .createProject(this.project.name, this.project.public ? 1 : 0) .subscribe( status=>{ this.create.emit(true); @@ -33,7 +34,7 @@ export class CreateProjectComponent { }, error=>{ this.hasError = true; - if (error instanceof Response) { + if (error instanceof Response) { switch(error.status) { case 409: this.errorMessage = 'Project name already exists.'; break; @@ -41,6 +42,7 @@ export class CreateProjectComponent { this.errorMessage = 'Project name is illegal.'; break; default: this.errorMessage = 'Unknown error for project name.'; + this.messageService.announceMessage(this.errorMessage); } } }); diff --git a/harbor-app/src/app/project/filter-project/filter-project.component.html b/harbor-app/src/app/project/filter-project/filter-project.component.html index d44a24e35..44d600707 100644 --- a/harbor-app/src/app/project/filter-project/filter-project.component.html +++ b/harbor-app/src/app/project/filter-project/filter-project.component.html @@ -1,5 +1,5 @@ - diff --git a/harbor-app/src/app/project/list-project/list-project.component.html b/harbor-app/src/app/project/list-project/list-project.component.html index 56fc667a1..fef985be2 100644 --- a/harbor-app/src/app/project/list-project/list-project.component.html +++ b/harbor-app/src/app/project/list-project/list-project.component.html @@ -1,19 +1,27 @@ - + Name Public/Private Repositories Creation time - Destination - Owner - Description - + Description + + {{p.name}} {{p.public == 1 ? 'Public': 'Private'}} {{p.repo_count}} {{p.creation_time}} - -- - {{p.owner}} - {{p.description}} + + {{p.description}} + + + + + + + {{ (projects ? projects.length : 0) }} item(s) \ No newline at end of file diff --git a/harbor-app/src/app/project/list-project/list-project.component.ts b/harbor-app/src/app/project/list-project/list-project.component.ts index 3d993d88e..a2ae4147a 100644 --- a/harbor-app/src/app/project/list-project/list-project.component.ts +++ b/harbor-app/src/app/project/list-project/list-project.component.ts @@ -1,4 +1,4 @@ -import { Component } from '@angular/core'; +import { Component, EventEmitter, Output } from '@angular/core'; import { Project } from '../project'; import { ProjectService } from '../project.service'; @@ -12,6 +12,10 @@ export class ListProjectComponent { projects: Project[]; errorMessage: string; + selected = []; + + @Output() actionPerform = new EventEmitter(); + constructor(private projectService: ProjectService) {} retrieve(name: string, isPublic: number): void { @@ -21,4 +25,37 @@ export class ListProjectComponent { response => this.projects = response, error => this.errorMessage = error); } + + toggleProject(p: Project) { + this.projectService + .toggleProjectPublic(p.project_id, p.public) + .subscribe( + response=>console.log(response), + error=>console.log(error) + ); + } + + deleteProject(p: Project) { + this.projectService + .deleteProject(p.project_id) + .subscribe( + response=>{ + console.log(response); + this.actionPerform.emit(true); + }, + error=>console.log(error) + ); + } + + deleteSelectedProjects() { + this.selected.forEach(p=>this.deleteProject(p)); + } + + onEdit(p: Project) { + + } + + onDelete(p: Project) { + + } } \ No newline at end of file diff --git a/harbor-app/src/app/project/project.component.html b/harbor-app/src/app/project/project.component.html index a8c04767d..e359bf212 100644 --- a/harbor-app/src/app/project/project.component.html +++ b/harbor-app/src/app/project/project.component.html @@ -1,13 +1,15 @@

Projects

- + + +
- +
\ No newline at end of file diff --git a/harbor-app/src/app/project/project.component.ts b/harbor-app/src/app/project/project.component.ts index 148f2c417..bca32cf33 100644 --- a/harbor-app/src/app/project/project.component.ts +++ b/harbor-app/src/app/project/project.component.ts @@ -3,6 +3,7 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { Router } from '@angular/router'; import { ListProjectComponent } from './list-project/list-project.component'; +import { CreateProjectComponent } from './create-project/create-project.component'; @Component({ selector: 'project', @@ -13,8 +14,20 @@ export class ProjectComponent implements OnInit { @ViewChild(ListProjectComponent) listProjects: ListProjectComponent; + + @ViewChild(CreateProjectComponent) + creationProject: CreateProjectComponent; + lastFilteredType: number = 0; + openModal(): void { + this.creationProject.newProject(); + } + + deleteSelectedProjects(): void { + this.listProjects.deleteSelectedProjects(); + } + createProject(created: boolean): void { console.log('Project has been created:' + created); this.listProjects.retrieve('', 0); @@ -32,6 +45,10 @@ export class ProjectComponent implements OnInit { this.listProjects.retrieve(projectName, this.lastFilteredType); } + actionPerform(performed: boolean): void { + this.listProjects.retrieve('', 0); + } + ngOnInit(): void { this.listProjects.retrieve('', 0); } diff --git a/harbor-app/src/app/project/project.module.ts b/harbor-app/src/app/project/project.module.ts index e5d006764..d1704bd66 100644 --- a/harbor-app/src/app/project/project.module.ts +++ b/harbor-app/src/app/project/project.module.ts @@ -9,12 +9,15 @@ import { ProjectComponent } from './project.component'; import { CreateProjectComponent } from './create-project/create-project.component'; import { SearchProjectComponent } from './search-project/search-project.component'; import { FilterProjectComponent } from './filter-project/filter-project.component'; +import { ActionProjectComponent } from './action-project/action-project.component'; import { ListProjectComponent } from './list-project/list-project.component'; import { ProjectDetailComponent } from './project-detail/project-detail.component'; + import { MemberComponent } from './member/member.component'; import { ProjectRoutingModule } from './project-routing.module'; import { ProjectService } from './project.service'; +import { DATAGRID_DIRECTIVES } from 'clarity-angular'; @NgModule({ imports: [ @@ -29,9 +32,10 @@ import { ProjectService } from './project.service'; CreateProjectComponent, SearchProjectComponent, FilterProjectComponent, + ActionProjectComponent, ListProjectComponent, ProjectDetailComponent, - MemberComponent + MemberComponent ], exports: [ ListProjectComponent ], providers: [ ProjectService ] diff --git a/harbor-app/src/app/project/project.service.ts b/harbor-app/src/app/project/project.service.ts index 75ca04356..38f521124 100644 --- a/harbor-app/src/app/project/project.service.ts +++ b/harbor-app/src/app/project/project.service.ts @@ -8,6 +8,7 @@ import { BaseService } from '../service/base.service'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; +import 'rxjs/add/observable/throw'; @Injectable() export class ProjectService extends BaseService { @@ -29,10 +30,23 @@ export class ProjectService extends BaseService { createProject(name: string, isPublic: number): Observable { return this.http .post(`/ng/api/projects`, - JSON.stringify({'project_name': name, 'public': (isPublic ? 1 : 0)}) + JSON.stringify({'project_name': name, 'public': isPublic}) , this.options) .map(response=>response.status) .catch(error=>Observable.throw(error)); } + toggleProjectPublic(projectId: number, isPublic: number): Observable { + return this.http + .put(`/ng/api/projects/${projectId}/publicity`, { 'public': isPublic }, this.options) + .map(response=>response.status) + .catch(error=>Observable.throw(error)); + } + + deleteProject(projectId: number): Observable { + return this.http + .delete(`/ng/api/projects/${projectId}`) + .map(response=>response.status) + .catch(error=>Observable.throw(error)); + } } \ No newline at end of file diff --git a/harbor-app/src/app/project/project.ts b/harbor-app/src/app/project/project.ts index 1c6d73014..2d2c10aed 100644 --- a/harbor-app/src/app/project/project.ts +++ b/harbor-app/src/app/project/project.ts @@ -29,4 +29,5 @@ export class Project { update_time: Date; current_user_role_id: number; repo_count: number; + selected: boolean; } \ No newline at end of file