Skip to content

Commit

Permalink
added changing branch sequences values
Browse files Browse the repository at this point in the history
  • Loading branch information
godfryd committed Mar 4, 2023
1 parent 9016806 commit 14998de
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 61 deletions.
26 changes: 26 additions & 0 deletions server/kraken/server/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,32 @@ def get_branch_sequences(branch_id, token_info=None):
return {'items': seqs, 'total': len(seqs)}, 200


def update_branch_sequence(seq_id, body, token_info=None):
seq = BranchSequence.query.filter_by(id=seq_id).one_or_none()
if seq is None:
abort(404, "Branch sequence not found")

access.check(token_info, seq.branch.project_id, 'pwrusr',
'only superadmin, project admin and project power user roles can get branch sequences')

value = body.get('value', None)
if value is None:
abort(400, "Missing value")

try:
value = int(value)
except Exception:
abort(400, "Incorrect value")

if value < -1:
abort(400, "Incorrect negative value")

seq.value = value
db.session.commit()

return seq.get_json(), 200


def move_branch(branch_id, body, token_info=None):
branch = Branch.query.filter_by(id=branch_id).one_or_none()
if branch is None:
Expand Down
37 changes: 37 additions & 0 deletions server/kraken/server/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,43 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ApiError'
/sequences/{seq_id}:
put:
tags:
- Management
summary: Set branch sequence value
operationId: update_branch_sequence
parameters:
- name: seq_id
in: path
description: ID of sequence
required: true
schema:
type: integer
format: int64
requestBody:
description: Value
content:
application/json:
schema:
type: object
properties:
value:
type: integer
format: int64
responses:
200:
description: An array of branch sequences
content:
application/json:
schema:
$ref: '#/components/schemas/BranchSequence'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/ApiError'
/branches/{branch_id}/stats:
get:
tags:
Expand Down
4 changes: 3 additions & 1 deletion ui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ import { ToolsPageComponent } from './tools-page/tools-page.component'
import { UsersPageComponent } from './users-page/users-page.component'
import { ChangePasswdDlgComponent } from './change-passwd-dlg/change-passwd-dlg.component'
import { LogsPanelComponent } from './logs-panel/logs-panel.component';
import { SimpleLogsPanelComponent } from './simple-logs-panel/simple-logs-panel.component'
import { SimpleLogsPanelComponent } from './simple-logs-panel/simple-logs-panel.component';
import { SequencesPanelComponent } from './sequences-panel/sequences-panel.component'
Chart.register(zoomPlugin)

@NgModule({
Expand Down Expand Up @@ -142,6 +143,7 @@ Chart.register(zoomPlugin)
ChangePasswdDlgComponent,
LogsPanelComponent,
SimpleLogsPanelComponent,
SequencesPanelComponent,
],
imports: [
BrowserModule,
Expand Down
21 changes: 2 additions & 19 deletions ui/src/app/branch-mgmt/branch-mgmt.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -407,29 +407,12 @@ <h3>Generated Step Code</h3>

<!-- Stats & Charts TAB -->
<app-tabbed-page-tab label="Stats & Charts">
<app-branch-stats [branch_id]="branchId"></app-branch-stats>
<app-branch-stats [branchId]="branchId"></app-branch-stats>
</app-tabbed-page-tab>

<!-- Sequences TAB -->
<app-tabbed-page-tab label="Sequences">
<table class="seqs-table">
<tr>
<th>Sequence Type</th>
<th>Stage</th>
<th>Value</th>
</tr>
<tr *ngFor="let s of sequences">
<td style="text-align: right;">
{{ getSeqTypeName(s) }}
</td>
<td>
{{ s.stage_name ? s.stage_name : '' }}
</td>
<td style="text-align: right;">
{{ s.value }}
</td>
</tr>
</table>
<app-sequences-panel [branchId]="branchId"></app-sequences-panel>
</app-tabbed-page-tab>

<!--
Expand Down
11 changes: 0 additions & 11 deletions ui/src/app/branch-mgmt/branch-mgmt.component.sass
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,6 @@
color: #fff


// sequences table
table.seqs-table
border-collapse: collapse


.seqs-table table, th, td
border: 1px solid black

.seqs-table th, td
padding: 7px 15px

// step fields table
.step-help-table
border-collapse: collapse
Expand Down
28 changes: 0 additions & 28 deletions ui/src/app/branch-mgmt/branch-mgmt.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ export class BranchMgmtComponent implements OnInit, OnDestroy {
git_clone_params: new UntypedFormControl(''),
})

sequences = []

retentionPolicyForm = this.fb.group({
ci_logs: [''],
dev_logs: [''],
Expand Down Expand Up @@ -241,14 +239,6 @@ export class BranchMgmtComponent implements OnInit, OnDestroy {
this.breadcrumbService.setCrumbs(crumbs)
})
)

this.subs.add(
this.managementService
.getBranchSequences(this.branchId)
.subscribe((data) => {
this.sequences = data.items
})
)
}

selectStage(stage) {
Expand Down Expand Up @@ -603,24 +593,6 @@ export class BranchMgmtComponent implements OnInit, OnDestroy {
)
}

getSeqTypeName(seq) {
switch (seq.kind) {
case 0:
return 'flow'
case 1:
return 'CI flow'
case 2:
return 'DEV flow'
case 3:
return 'run'
case 4:
return 'CI run'
case 5:
return 'DEV run'
}
return 'unknown'
}

deleteBranch() {
this.subs.add(
this.managementService.deleteBranch(this.branchId).subscribe(
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/branch-stats/branch-stats.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ManagementService } from '../backend/api/management.service'
styleUrls: ['./branch-stats.component.sass'],
})
export class BranchStatsComponent implements OnInit, OnDestroy {
@Input() branch_id: number
@Input() branchId: number

stats: any = null

Expand All @@ -30,7 +30,7 @@ export class BranchStatsComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.subs.add(
this.managementService
.getBranchStats(this.branch_id)
.getBranchStats(this.branchId)
.subscribe((data) => {
this.stats = data

Expand Down
40 changes: 40 additions & 0 deletions ui/src/app/sequences-panel/sequences-panel.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!-- change branch names dialog -->
<p-dialog header="Change sequence value" [(visible)]="changeSeqDlgVisible" [style]="{width: '30rem'}">
<div class="field grid" *ngIf="selectedSeq">
<label for="sequenceVal" class="col-fixed" style="width: 10rem;">New Value</label>
<div class="col">
<p-inputNumber inputId="sequenceVal" [(ngModel)]="selectedSeq.value" mode="decimal" [min]="-1">
</p-inputNumber>
</div>
</div>

<p-footer>
<button type="button" (click)="cancelChangeSeqValue()" pButton icon="pi pi-times" label="Cancel" class="p-button-outlined p-button-secondary"></button>
<button type="button" (click)="changeSeqValue()" pButton icon="pi pi-check" label="Set"></button>
</p-footer>
</p-dialog>

<div>
<table class="seqs-table">
<tr>
<th>Sequence Type</th>
<th>Stage</th>
<th>Value</th>
<th>Change</th>
</tr>
<tr *ngFor="let s of sequences">
<td style="text-align: right;">
{{ getSeqTypeName(s) }}
</td>
<td>
{{ s.stage_name ? s.stage_name : '' }}
</td>
<td style="text-align: right;">
{{ s.value }}
</td>
<td>
<button pButton type="button" icon="pi pi-pencil" class="p-button-sm" (click)="showSeqChangeDlg(s)"></button>
</td>
</tr>
</table>
</div>
10 changes: 10 additions & 0 deletions ui/src/app/sequences-panel/sequences-panel.component.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// sequences table
table.seqs-table
border-collapse: collapse


.seqs-table table, th, td
border: 1px solid black

.seqs-table th, td
padding: 7px 15px
23 changes: 23 additions & 0 deletions ui/src/app/sequences-panel/sequences-panel.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { SequencesPanelComponent } from './sequences-panel.component';

describe('SequencesPanelComponent', () => {
let component: SequencesPanelComponent;
let fixture: ComponentFixture<SequencesPanelComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ SequencesPanelComponent ]
})
.compileComponents();

fixture = TestBed.createComponent(SequencesPanelComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
96 changes: 96 additions & 0 deletions ui/src/app/sequences-panel/sequences-panel.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Component, OnInit, OnDestroy, Input } from '@angular/core';

import { Subscription } from 'rxjs'

import { MessageService } from 'primeng/api'

import { ManagementService } from '../backend/api/management.service'
import { showErrorBox } from '../utils'


@Component({
selector: 'app-sequences-panel',
templateUrl: './sequences-panel.component.html',
styleUrls: ['./sequences-panel.component.sass']
})
export class SequencesPanelComponent implements OnInit, OnDestroy {
@Input() branchId: number

sequences = []
selectedSeq: any = null

changeSeqDlgVisible = false

private subs: Subscription = new Subscription()

constructor(
protected managementService: ManagementService,
private msgSrv: MessageService
) { }

ngOnInit(): void {
this.subs.add(
this.managementService
.getBranchSequences(this.branchId)
.subscribe((data) => {
this.sequences = data.items
})
)
}

ngOnDestroy() {
this.subs.unsubscribe()
}

getSeqTypeName(seq) {
switch (seq.kind) {
case 0:
return 'flow'
case 1:
return 'CI flow'
case 2:
return 'DEV flow'
case 3:
return 'run'
case 4:
return 'CI run'
case 5:
return 'DEV run'
}
return 'unknown'
}

showSeqChangeDlg(seq) {
this.selectedSeq = seq
this.changeSeqDlgVisible = true
}

cancelChangeSeqValue() {
this.changeSeqDlgVisible = false
}

changeSeqValue() {
this.subs.add(
this.managementService
.updateBranchSequence(this.selectedSeq.id, {value: this.selectedSeq.value})
.subscribe(
(data) => {
this.changeSeqDlgVisible = false
this.msgSrv.add({
severity: 'success',
summary: 'Update of branch sequence value succeeded',
detail: 'Update of branch sequence value succeeded.',
})
},
(err) => {
this.changeSeqDlgVisible = false
showErrorBox(
this.msgSrv,
err,
'Updating branch sequence value erred'
)
}
)
)
}
}

0 comments on commit 14998de

Please sign in to comment.