Skip to content

Commit

Permalink
feat (ui): repository parameter. Close #537 (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored and yesnault committed Apr 28, 2017
1 parent bde721f commit 57e9034
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
19 changes: 15 additions & 4 deletions ui/src/app/shared/parameter/value/parameter.value.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class ParameterValueComponent implements OnInit {
@Input() editList = true;
@Input() edit = true;
@Input() suggest: Array<string> = new Array<string>();
@Input() projectKey: string;
@Input('project')
set project(data: Project) {
this.repositoriesManager = new Array<RepositoriesManager>();
Expand All @@ -30,9 +31,13 @@ export class ParameterValueComponent implements OnInit {
name: 'Git Url'
});
if (data && data.repositories_manager) {
this.repositoriesManager = _.cloneDeep(data.repositories_manager);
this.repositoriesManager.push(..._.cloneDeep(data.repositories_manager));
}
this.selectedRepoManager = this.repositoriesManager[0];
if (data) {
this.projectKey = data.key;
}

}

@Output() valueChange = new EventEmitter<string|number|boolean>();
Expand All @@ -46,7 +51,7 @@ export class ParameterValueComponent implements OnInit {
repositoriesManager: Array<RepositoriesManager>;
repositories: Array<Repository>;
selectedRepoManager: RepositoriesManager;
selectedRepo: Repository;
selectedRepo: string;
loadingRepos: boolean;

list: Array<string>;
Expand Down Expand Up @@ -111,10 +116,14 @@ export class ParameterValueComponent implements OnInit {

updateRepoManager(name: string): void {
this.selectedRepoManager = this.repositoriesManager.find(r => r.name === name);
if (this.selectedRepoManager.url !== 'Git') {
this.updateListRepo();
}
}

valueRepoChanged(name): void {
this.value = this.selectedRepoManager.name + '##' + this.selectedRepo.name;
this.value = this.selectedRepoManager.name + '##' + name;
this.valueChanged();
}

/**
Expand All @@ -123,8 +132,10 @@ export class ParameterValueComponent implements OnInit {
updateListRepo(): void {
if (this.selectedRepoManager) {
this.loadingRepos = true;
this._repoManagerService.getRepositories(this.project.key, this.selectedRepoManager.name)
delete this.selectedRepo;
this._repoManagerService.getRepositories(this.projectKey, this.selectedRepoManager.name)
.subscribe( repos => {
this.selectedRepo = repos[0].fullname;
this.repositories = repos;
this.loadingRepos = false;
}, () => {
Expand Down
7 changes: 4 additions & 3 deletions ui/src/app/shared/parameter/value/parameter.value.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
<option *ngFor="let r of repositoriesManager" value="{{r.name}}">{{r.name}}</option>
</sm-select>
<sm-select *ngIf="selectedRepoManager && selectedRepoManager.name !== 'Git Url'"
(modelChange)="valueRepoChanged()"
placeholder="Loading..."
(modelChange)="valueRepoChanged($event)"
[(model)]="selectedRepo"
class="search item"
[disabled]="loadingBtn">
[disabled]="loadingRepos">
<option *ngFor="let r of repositories" value="{{r.fullname}}">{{r.fullname}}</option>
</sm-select>
<input type="text" [(ngModel)]="value" (change)="valueChanged()" (keydown)="sendValueChanged()" name="value" placeholder="{{'parameter_git_url' | translate }}">
<input *ngIf="selectedRepoManager && selectedRepoManager.name === 'Git Url'" type="text" [(ngModel)]="value" (change)="valueChanged()" (keydown)="sendValueChanged()" name="value" placeholder="{{'parameter_git_url' | translate }}">
</div>
<div *ngSwitchDefault class="ui fluid input">
<input auto-complete autocomplete="off" type="text" [(ngModel)]="value"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {Template, ApplyTemplateRequest} from '../../../model/template.model';
import {Parameter} from '../../../model/parameter.model';
import {Application} from '../../../model/application.model';
import {Variable} from '../../../model/variable.model';
import {VariableService} from '../../../service/variable/variable.service';

describe('CDS: Application Add Component', () => {

Expand All @@ -49,7 +50,8 @@ describe('CDS: Application Add Component', () => {
TranslateService,
TranslateLoader,
TranslateParser,
ApplicationTemplateService
ApplicationTemplateService,
VariableService
],
imports : [
ApplicationModule,
Expand Down
15 changes: 12 additions & 3 deletions ui/src/app/views/application/add/application.add.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component} from '@angular/core';
import {Component, OnInit} from '@angular/core';
import {ApplyTemplateRequest, Template} from '../../../model/template.model';
import {ApplicationTemplateService} from '../../../service/application/application.template.service';
import {ActivatedRoute, Router} from '@angular/router';
Expand All @@ -9,6 +9,7 @@ import {ApplicationStore} from '../../../service/application/application.store';
import {Parameter} from '../../../model/parameter.model';
import {TranslateService} from 'ng2-translate';
import {ToastService} from '../../../shared/toast/ToastService';
import {VariableService} from '../../../service/variable/variable.service';

declare var _: any;

Expand All @@ -17,7 +18,7 @@ declare var _: any;
templateUrl: './application.add.html',
styleUrls: ['./application.add.scss']
})
export class ApplicationAddComponent {
export class ApplicationAddComponent implements OnInit {

ready = false;
project: Project;
Expand All @@ -35,9 +36,11 @@ export class ApplicationAddComponent {
applicationNamePattern: RegExp = new RegExp('^[a-zA-Z0-9._-]{1,}$');
appPatternError = false;

suggestion: Array<string>;

constructor(private _appTemplateService: ApplicationTemplateService, private _activatedRoute: ActivatedRoute,
private _appStore: ApplicationStore, private _toast: ToastService, private _translate: TranslateService,
private _router: Router) {
private _router: Router, private _varService: VariableService) {
this._activatedRoute.data.subscribe( datas => {
this.project = datas['project'];
});
Expand All @@ -48,6 +51,12 @@ export class ApplicationAddComponent {
});
}

ngOnInit(): void {
this._varService.getContextVariable(this.project.key).first().subscribe( s => {
this.suggestion = s;
});
}

updateSelection(type): void {
switch (type) {
case 'clone':
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/views/application/add/application.add.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2>{{ 'application_create' | translate }}</h2>


<div class="field" *ngIf="parameters && parameters.length > 0">
<app-parameter-list [parameters]="parameters" mode="launcher"></app-parameter-list>
<app-parameter-list [parameters]="parameters" mode="launcher" [project]="project" [suggest]="suggestion"></app-parameter-list>
</div>
<div class="field" *ngIf="variables && variables.length > 0">
<app-variable [variables]="variables" mode="launcher"></app-variable>
Expand Down

0 comments on commit 57e9034

Please sign in to comment.