-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration view to create labels (#1564)
- Loading branch information
1 parent
f8f8e51
commit 499e060
Showing
16 changed files
with
557 additions
and
5 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
ui/projects/streampipes/platform-services/src/lib/apis/labels.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import { Injectable } from '@angular/core'; | ||
import { SpLabel } from '../model/labels/labels.model'; | ||
import { Observable } from 'rxjs'; | ||
import { GenericStorageService } from './generic-storage.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class LabelsService { | ||
appDocType = 'sp-labels'; | ||
|
||
constructor(private genericStorageService: GenericStorageService) {} | ||
|
||
getAllLabels(): Observable<SpLabel[]> { | ||
return this.genericStorageService.getAllDocuments(this.appDocType); | ||
} | ||
|
||
addLabel(label: SpLabel): Observable<SpLabel> { | ||
if (!label.appDocType) { | ||
label.appDocType = this.appDocType; | ||
} | ||
return this.genericStorageService.createDocument( | ||
this.appDocType, | ||
label, | ||
); | ||
} | ||
|
||
getLabel(id: string): Observable<SpLabel> { | ||
return this.genericStorageService.getDocument(this.appDocType, id); | ||
} | ||
|
||
deleteLabel(id: string, rev: string): Observable<any> { | ||
return this.genericStorageService.deleteDocument( | ||
this.appDocType, | ||
id, | ||
rev, | ||
); | ||
} | ||
|
||
updateLabel(label: SpLabel) { | ||
return this.genericStorageService.updateDocument( | ||
this.appDocType, | ||
label, | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
ui/projects/streampipes/platform-services/src/lib/model/labels/labels.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
export interface SpLabel { | ||
appDocType?: string; | ||
_id?: string; | ||
_rev?: string; | ||
label: string; | ||
description: string; | ||
color: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
ui/projects/streampipes/shared-ui/src/lib/components/sp-label/sp-label.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!-- | ||
~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
~ contributor license agreements. See the NOTICE file distributed with | ||
~ this work for additional information regarding copyright ownership. | ||
~ The ASF licenses this file to You under the Apache License, Version 2.0 | ||
~ (the "License"); you may not use this file except in compliance with | ||
~ the License. You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~ | ||
--> | ||
|
||
<span | ||
class="basic-label" | ||
[ngStyle]="{ | ||
background: labelBackground, | ||
borderColor: 'color-mix(in srgb, ' + labelBackground + ' 70%, black)', | ||
color: labelTextColor | ||
}" | ||
> | ||
{{ labelText }} | ||
</span> |
27 changes: 27 additions & 0 deletions
27
ui/projects/streampipes/shared-ui/src/lib/components/sp-label/sp-label.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*! | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
.basic-label { | ||
border-radius: 15px; | ||
min-width: 50px; | ||
height: 20px; | ||
padding: 5px 7px; | ||
border: 1px solid; | ||
display: inline-block; | ||
text-align: center; | ||
} |
54 changes: 54 additions & 0 deletions
54
ui/projects/streampipes/shared-ui/src/lib/components/sp-label/sp-label.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import { Component, Input, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'sp-label', | ||
templateUrl: './sp-label.component.html', | ||
styleUrls: ['./sp-label.component.scss'], | ||
}) | ||
export class SpLabelComponent implements OnInit { | ||
@Input() | ||
labelText: string; | ||
|
||
_labelBackground: string; | ||
|
||
labelTextColor = ''; | ||
|
||
ngOnInit(): void {} | ||
|
||
@Input() | ||
set labelBackground(labelBackground: string) { | ||
this._labelBackground = labelBackground; | ||
this.labelTextColor = this.generateContrastColor(labelBackground); | ||
} | ||
|
||
get labelBackground(): string { | ||
return this._labelBackground; | ||
} | ||
|
||
generateContrastColor(bgColor) { | ||
const color = | ||
bgColor.charAt(0) === '#' ? bgColor.substring(1, 7) : bgColor; | ||
const r = parseInt(color.substring(0, 2), 16); | ||
const g = parseInt(color.substring(2, 4), 16); | ||
const b = parseInt(color.substring(4, 6), 16); | ||
return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? '#000' : '#FFF'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
ui/src/app/configuration/label-configuration/edit-label/edit-label.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<!-- | ||
~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
~ contributor license agreements. See the NOTICE file distributed with | ||
~ this work for additional information regarding copyright ownership. | ||
~ The ASF licenses this file to You under the Apache License, Version 2.0 | ||
~ (the "License"); you may not use this file except in compliance with | ||
~ the License. You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~ | ||
--> | ||
|
||
<div fxLayout="column" class="mt-10" [ngClass]="editMode ? '' : 'create-label'"> | ||
<div | ||
fxLayout="row" | ||
fxFlex="100" | ||
fxLayoutGap="10px" | ||
fxLayoutAlign="start center" | ||
> | ||
<sp-label | ||
[labelBackground]="label.color" | ||
[labelText]="label.label" | ||
*ngIf="label && showPreview" | ||
></sp-label> | ||
<mat-form-field color="accent"> | ||
<mat-label>Label</mat-label> | ||
<input matInput [(ngModel)]="label.label" /> | ||
</mat-form-field> | ||
<mat-form-field color="accent"> | ||
<mat-label>Desription</mat-label> | ||
<input matInput [(ngModel)]="label.description" /> | ||
</mat-form-field> | ||
<mat-form-field color="accent"> | ||
<input | ||
matInput | ||
[(colorPicker)]="label.color" | ||
[cpPosition]="'bottom'" | ||
[style.background]="label.color" | ||
/> | ||
</mat-form-field> | ||
<div fxFlex fxLayoutAlign="end center"> | ||
<button | ||
mat-button | ||
mat-raised-button | ||
class="mat-basic mr-5" | ||
(click)="cancelEmitter.emit()" | ||
> | ||
Cancel | ||
</button> | ||
<button | ||
mat-button | ||
mat-raised-button | ||
color="accent" | ||
(click)="saveEmitter.emit(label)" | ||
> | ||
Save | ||
</button> | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.