Skip to content

Commit

Permalink
Merge pull request winery#528 from OpenTOSCA/thesis/version-slider
Browse files Browse the repository at this point in the history
Add version slider in topology modeler
  • Loading branch information
lharzenetter authored Nov 24, 2020
2 parents 854673c + ba0d000 commit ed69d86
Show file tree
Hide file tree
Showing 14 changed files with 348 additions and 39 deletions.
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Copyright (c) 2017 Yannic Sowoidnich
Copyright (c) 2017-2018 Thommy Zelenik
Copyright (c) 2017 Tino Stadelmaier
Copyright (c) 2017 ZTE Coperation
Copyright (c) 2018 Adrian Wersching
Copyright (c) 2018, 2020 Adrian Wersching
Copyright (c) 2018-2020 Björn Müller
Copyright (c) 2018 Christoph Krieger
Copyright (c) 2018-2020 Ghareeb Falazi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ <h3 style="margin-right: .5em;">winery</h3>
</button>
</div>

<div *ngIf="showVersionSliderButton" class="btn-group button-group" data-toggle="buttons">
<button class="btn btn-sm align-middle dark-button-style" id="versionSlider"
(click)="toggleButton($event)"
[style.background-color]="getStyle(navbarButtonsState.buttonsState.versionSliderButton)">
Version Slider
</button>
</div>

<div *ngIf="!readonly" class="btn-group button-group" dropdown>
<button dropdownToggle type="button" class="btn btn-sm dark-button-style align-middle dropdown-toggle">
Other <span class="caret"></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { StatefulAnnotationsService } from '../services/statefulAnnotations.serv
import { FeatureEnum } from '../../../../tosca-management/src/app/wineryFeatureToggleModule/wineryRepository.feature.direct';
import { WineryRepositoryConfigurationService } from '../../../../tosca-management/src/app/wineryFeatureToggleModule/WineryRepositoryConfiguration.service';
import { TTopologyTemplate } from '../models/ttopology-template';
import { VersionSliderService } from '../version-slider/version-slider.service';

/**
* The navbar of the topologymodeler.
Expand Down Expand Up @@ -62,6 +63,7 @@ export class NavbarComponent implements OnDestroy {
splittingOngoing: boolean;
matchingOngoing: boolean;
placingOngoing: boolean;
showVersionSliderButton: boolean;
configEnum = FeatureEnum;

constructor(private alert: ToastrService,
Expand All @@ -71,6 +73,7 @@ export class NavbarComponent implements OnDestroy {
private backendService: BackendService,
private statefulService: StatefulAnnotationsService,
private hotkeysService: HotkeysService,
private versionSliderService: VersionSliderService,
public configurationService: WineryRepositoryConfigurationService) {
this.subscriptions.push(ngRedux.select(state => state.topologyRendererState)
.subscribe(newButtonsState => this.setButtonsState(newButtonsState)));
Expand All @@ -87,6 +90,8 @@ export class NavbarComponent implements OnDestroy {
return false; // Prevent bubbling
}, undefined, 'Apply the layout directive to the Node Templates'));
this.exportCsarUrl = this.backendService.serviceTemplateURL + '/?csar';
this.versionSliderService.hasMultipleVersions()
.subscribe(hasMultipleVersions => this.showVersionSliderButton = hasMultipleVersions);
}

/**
Expand Down Expand Up @@ -245,6 +250,11 @@ export class NavbarComponent implements OnDestroy {
case 'manageYamlPolicies':
this.ngRedux.dispatch(this.actions.manageYamlPolicies());
break;
case 'versionSlider':
this.readonly = true;
this.ngRedux.dispatch(this.wineryActions.sendPaletteOpened(false));
this.ngRedux.dispatch(this.actions.toggleVersionSlider());
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class TopologyRendererActions {
static CLEAN_FREEZABLE_COMPONENTS = 'CLEAN_FREEZABLE_COMPONENTS';
static PLACE_COMPONENTS = 'PLACE_COMPONENTS';
static MANAGE_YAML_POLICIES = 'MANAGE_YAML_POLICIES';
static TOGGLE_VERSION_SLIDER = 'TOGGLE_VERSION_SLIDER';

togglePolicies(): Action {
return { type: TopologyRendererActions.TOGGLE_POLICIES };
Expand Down Expand Up @@ -165,4 +166,8 @@ export class TopologyRendererActions {
manageYamlPolicies(): Action {
return { type: TopologyRendererActions.MANAGE_YAML_POLICIES };
}

toggleVersionSlider(): Action {
return { type: TopologyRendererActions.TOGGLE_VERSION_SLIDER };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface TopologyRendererState {
cleanFreezableComponentsButton?: boolean;
placeComponentsButton?: boolean;
manageYamlPoliciesButton?: boolean;
versionSliderButton?: boolean;
};
nodesToSelect?: string[];
}
Expand Down Expand Up @@ -74,7 +75,8 @@ export const INITIAL_TOPOLOGY_RENDERER_STATE: TopologyRendererState = {
determineFreezableComponentsButton: false,
cleanFreezableComponentsButton: false,
placeComponentsButton: false,
manageYamlPoliciesButton: false
manageYamlPoliciesButton: false,
versionSliderButton: false
}
};
/**
Expand Down Expand Up @@ -302,6 +304,14 @@ export const TopologyRendererReducer =
manageYamlPoliciesButton: !lastState.buttonsState.manageYamlPoliciesButton
}
};
case TopologyRendererActions.TOGGLE_VERSION_SLIDER:
return {
...lastState,
buttonsState: {
...lastState.buttonsState,
versionSliderButton: !lastState.buttonsState.versionSliderButton
}
};
}
return lastState;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*******************************************************************************/

.version-slider-view {
position: fixed;
bottom: 0;
z-index: 6;
left: 50%;
width: 75%;
transform: translate(-50%, -50%);
}

::ng-deep .version-slider-view .ngx-slider .ngx-slider-tick-legend {
width: 7em;
max-width: 7em;
}

::ng-deep .version-slider-view .ngx-slider {
width: calc(100% - 3.5em - 1em);
}

#open {
margin-left: 1em;
margin-bottom: 3px;
width: 3.5em;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright (c) 2020 Contributors to the Eclipse Foundation
~
~ See the NOTICE file(s) distributed with this work for additional
~ information regarding copyright ownership.
~
~ This program and the accompanying materials are made available under the
~ terms of the Eclipse Public License 2.0 which is available at
~ http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0
~ which is available at https://www.apache.org/licenses/LICENSE-2.0.
~
~ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->

<div *ngIf="options.stepsArray"
class="version-slider-view">
<ngx-slider [(value)]="sliderValue"
[options]="options"
(userChange)="updateTopologyTemplate()">
</ngx-slider>
<button id="open"
class="btn btn-sm align-middle btn-info button-group"
[disabled]="selectedIsCurrent()"
(click)="open()">
Open
</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*******************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*******************************************************************************/

import { Component, OnInit } from '@angular/core';
import { VersionSliderService } from './version-slider.service';
import { Options } from '@angular-slider/ngx-slider';
import { WineryVersion } from '../../../../tosca-management/src/app/model/wineryVersion';
import { BackendService } from '../services/backend.service';
import { TopologyTemplateUtil } from '../models/topologyTemplateUtil';
import { NgRedux } from '@angular-redux/store';
import { IWineryState } from '../redux/store/winery.store';
import { TopologyRendererActions } from '../redux/actions/topologyRenderer.actions';
import { WineryActions } from '../redux/actions/winery.actions';
import { WineryRepositoryConfigurationService } from '../../../../tosca-management/src/app/wineryFeatureToggleModule/WineryRepositoryConfiguration.service';

@Component({
selector: 'winery-version-slider',
templateUrl: './version-slider.component.html',
styleUrls: ['./version-slider.component.css']
})
export class VersionSliderComponent implements OnInit {
private static readonly LEGEND_CHAR_LIMIT = 15;

sliderValue: number;
versions: WineryVersion[];
options: Options = {
showTicksValues: true,
stepsArray: undefined,
translate: VersionSliderComponent.hideValues
};

constructor(private versionSliderService: VersionSliderService,
private backendService: BackendService,
private ngRedux: NgRedux<IWineryState>,
private rendererActions: TopologyRendererActions,
private wineryActions: WineryActions,
private configurationService: WineryRepositoryConfigurationService) {
this.versionSliderService.getVersions()
.subscribe(versions => this.init(versions));
}

ngOnInit() {
}

private init(versions: WineryVersion[]) {
this.versions = versions;

const id = this.backendService.configuration.id;
this.sliderValue = this.versions
.findIndex(v => this.toId(v) === id);

const stepsArray = [];
this.versions.forEach((version, index) => {
const legend = VersionSliderComponent.limitChars(version.toReadableString());
stepsArray.push({ value: index, legend });
});
// trigger change detection
const newOptions: Options = Object.assign({}, this.options);
newOptions.stepsArray = stepsArray;
this.options = newOptions;
}

updateTopologyTemplate() {
const version = this.getSelectedVersion();
const id = this.toId(version);

this.versionSliderService.getTopologyTemplate(id)
.subscribe(topologyTemplate => {
TopologyTemplateUtil.updateTopologyTemplate(
this.ngRedux,
this.wineryActions,
topologyTemplate,
this.configurationService.isYaml()
);
}
);
}

selectedIsCurrent(): boolean {
return this.toId(this.getSelectedVersion())
=== this.backendService.configuration.id;
}

open() {
const version = this.getSelectedVersion();
const id = this.toId(version);
let editorConfig = '?repositoryURL=' + encodeURIComponent(this.backendService.configuration.repositoryURL)
+ '&uiURL=' + encodeURIComponent(this.backendService.configuration.uiURL)
+ '&ns=' + encodeURIComponent(this.backendService.configuration.ns)
+ '&id=' + id;
if (!version.editable) {
editorConfig += '&isReadonly=true';
}
window.open(editorConfig, '_blank');
}

private getSelectedVersion() {
return this.versions[this.sliderValue];
}

private toId(version: WineryVersion): string {
return VersionSliderComponent.getName(this.backendService.configuration.id)
+ WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR
+ version.toString();
}

private static getName(id: string) {
return id.split(WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR)[0];
}

private static hideValues(): string {
return '';
}

private static limitChars(str: string): string {
if (str.length < this.LEGEND_CHAR_LIMIT) {
return str;
} else {
return str.substr(0, this.LEGEND_CHAR_LIMIT) + '...';
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*******************************************************************************/

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { BackendService } from '../services/backend.service';
import { WineryVersion } from '../../../../tosca-management/src/app/model/wineryVersion';
import { Observable } from 'rxjs';
import { TTopologyTemplate } from '../models/ttopology-template';

@Injectable()
export class VersionSliderService {

constructor(private http: HttpClient,
private backendService: BackendService) {
}

getVersions(): Observable<WineryVersion[]> {
const url = this.backendService.configuration.parentElementUrl + '?versions';
return this.http.get<WineryVersion[]>(url)
.map(array => array.reverse())
// recreate class to access methods
.map(array => array.map(v => VersionSliderService.toWineryVersion(v)));
}

hasMultipleVersions(): Observable<boolean> {
return this.getVersions()
.map(versions => versions && versions.length > 1);
}

getTopologyTemplate(id: string): Observable<TTopologyTemplate> {
const url = this.backendService.configuration.repositoryURL + '/'
+ 'servicetemplates/'
+ encodeURIComponent(encodeURIComponent(this.backendService.configuration.ns)) + '/'
+ id + '/'
+ 'topologytemplate';
return this.http.get<TTopologyTemplate>(url);
}

private static toWineryVersion(wv: any): WineryVersion {
return new WineryVersion(
wv.componentVersion,
wv.wineryVersion,
wv.workInProgressVersion,
wv.currentVersion,
wv.latestVersion,
wv.releasable,
wv.editable
);
}
}
Loading

0 comments on commit ed69d86

Please sign in to comment.