Skip to content

Commit

Permalink
Add configuration view to create labels (#1564)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikriemer committed May 12, 2023
1 parent f8f8e51 commit 499e060
Show file tree
Hide file tree
Showing 16 changed files with 557 additions and 5 deletions.
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,
);
}
}
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;
}
2 changes: 2 additions & 0 deletions ui/projects/streampipes/platform-services/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export * from './lib/apis/files.service';
export * from './lib/apis/functions.service';
export * from './lib/apis/general-config.service';
export * from './lib/apis/generic-storage.service';
export * from './lib/apis/labels.service';
export * from './lib/apis/mail-config.service';
export * from './lib/apis/measurement-units.service';
export * from './lib/apis/permissions.service';
Expand Down Expand Up @@ -63,3 +64,4 @@ export * from './lib/query/data-view-query-generator.service';
export * from './lib/model/user/user.model';

export * from './lib/model/assets/asset.model';
export * from './lib/model/labels/labels.model';
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>
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;
}
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';
}
}
3 changes: 3 additions & 0 deletions ui/projects/streampipes/shared-ui/src/lib/shared-ui.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { SpExceptionMessageComponent } from './components/sp-exception-message/s
import { SpExceptionDetailsDialogComponent } from './components/sp-exception-message/exception-details-dialog/exception-details-dialog.component';
import { MatDividerModule } from '@angular/material/divider';
import { SplitSectionComponent } from './components/split-section/split-section.component';
import { SpLabelComponent } from './components/sp-label/sp-label.component';

@NgModule({
declarations: [
Expand All @@ -48,6 +49,7 @@ import { SplitSectionComponent } from './components/split-section/split-section.
SpBasicNavTabsComponent,
SpExceptionMessageComponent,
SpExceptionDetailsDialogComponent,
SpLabelComponent,
SplitSectionComponent,
],
imports: [
Expand All @@ -71,6 +73,7 @@ import { SplitSectionComponent } from './components/split-section/split-section.
SpBasicNavTabsComponent,
SpExceptionMessageComponent,
SpExceptionDetailsDialogComponent,
SpLabelComponent,
SplitSectionComponent,
],
})
Expand Down
1 change: 1 addition & 0 deletions ui/projects/streampipes/shared-ui/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export * from './lib/components/basic-nav-tabs/basic-nav-tabs.component';
export * from './lib/components/split-section/split-section.component';
export * from './lib/components/sp-exception-message/sp-exception-message.component';
export * from './lib/components/sp-exception-message/exception-details-dialog/exception-details-dialog.component';
export * from './lib/components/sp-label/sp-label.component';

export * from './lib/models/sp-navigation.model';

Expand Down
15 changes: 10 additions & 5 deletions ui/src/app/configuration/configuration-tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,21 @@ export class SpConfigurationTabs {
itemTitle: 'Data Lake',
itemLink: ['configuration', 'datalake'],
},
{
itemId: 'email',
itemTitle: 'Mail',
itemLink: ['configuration', 'email'],
},
{
itemId: 'export',
itemTitle: 'Export/Import',
itemLink: ['configuration', 'export'],
},
{
itemId: 'labels',
itemTitle: 'Labels',
itemLink: ['configuration', 'labels'],
},
{
itemId: 'email',
itemTitle: 'Mail',
itemLink: ['configuration', 'email'],
},
{
itemId: 'messaging',
itemTitle: 'Messaging',
Expand Down
10 changes: 10 additions & 0 deletions ui/src/app/configuration/configuration.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ import { SpDataExportImportComponent } from './export/data-export-import.compone
import { SpDataExportDialogComponent } from './export/export-dialog/data-export-dialog.component';
import { SpDataImportDialogComponent } from './export/import-dialog/data-import-dialog.component';
import { SpDataExportItemComponent } from './export/export-dialog/data-export-item/data-export-item.component';
import { SpEditLabelComponent } from './label-configuration/edit-label/edit-label.component';
import { SpLabelConfigurationComponent } from './label-configuration/label-configuration.component';
import { ColorPickerModule } from 'ngx-color-picker';

@NgModule({
imports: [
Expand Down Expand Up @@ -102,6 +105,10 @@ import { SpDataExportItemComponent } from './export/export-dialog/data-export-it
path: 'export',
component: SpDataExportImportComponent,
},
{
path: 'labels',
component: SpLabelConfigurationComponent,
},
{
path: 'messaging',
component: MessagingConfigurationComponent,
Expand All @@ -118,6 +125,7 @@ import { SpDataExportItemComponent } from './export/export-dialog/data-export-it
},
]),
SharedUiModule,
ColorPickerModule,
],
declarations: [
ConsulServiceComponent,
Expand All @@ -143,6 +151,8 @@ import { SpDataExportItemComponent } from './export/export-dialog/data-export-it
SpDataExportDialogComponent,
SpDataExportItemComponent,
SpDataImportDialogComponent,
SpEditLabelComponent,
SpLabelConfigurationComponent,
],
providers: [ConfigurationService],
})
Expand Down
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>
Loading

0 comments on commit 499e060

Please sign in to comment.