implement version editing
This commit is contained in:
parent
0649a6f402
commit
2921366c18
8 changed files with 183 additions and 35 deletions
|
@ -76,6 +76,14 @@ public class Version implements Comparable<Version>{
|
||||||
return mappings;
|
return mappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMappings(@Nullable String mappings) {
|
||||||
|
this.mappings = mappings;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(@NonNull Version o) {
|
public int compareTo(@NonNull Version o) {
|
||||||
return Integer.compare(code, o.code);
|
return Integer.compare(code, o.code);
|
||||||
|
|
|
@ -27,8 +27,6 @@ import com.faendir.acra.service.AvatarService;
|
||||||
import com.faendir.acra.ui.base.popup.Popup;
|
import com.faendir.acra.ui.base.popup.Popup;
|
||||||
import com.faendir.acra.ui.view.report.ReportView;
|
import com.faendir.acra.ui.view.report.ReportView;
|
||||||
import com.faendir.acra.util.TimeSpanRenderer;
|
import com.faendir.acra.util.TimeSpanRenderer;
|
||||||
import com.vaadin.flow.component.ClickEvent;
|
|
||||||
import com.vaadin.flow.component.ComponentEventListener;
|
|
||||||
import com.vaadin.flow.component.button.Button;
|
import com.vaadin.flow.component.button.Button;
|
||||||
import com.vaadin.flow.component.grid.Grid;
|
import com.vaadin.flow.component.grid.Grid;
|
||||||
import com.vaadin.flow.component.icon.Icon;
|
import com.vaadin.flow.component.icon.Icon;
|
||||||
|
@ -54,7 +52,7 @@ public class ReportList extends MyGrid<Report>{
|
||||||
addColumn(report -> report.getStacktrace().getStacktrace().split("\n", 2)[0], QReport.report.stacktrace.stacktrace, Messages.STACKTRACE).setFlexGrow(1);
|
addColumn(report -> report.getStacktrace().getStacktrace().split("\n", 2)[0], QReport.report.stacktrace.stacktrace, Messages.STACKTRACE).setFlexGrow(1);
|
||||||
if (SecurityUtils.hasPermission(app, Permission.Level.EDIT)) {
|
if (SecurityUtils.hasPermission(app, Permission.Level.EDIT)) {
|
||||||
addColumn(new ComponentRenderer<>(report -> new Button(new Icon(VaadinIcon.TRASH),
|
addColumn(new ComponentRenderer<>(report -> new Button(new Icon(VaadinIcon.TRASH),
|
||||||
(ComponentEventListener<ClickEvent<Button>>) event -> new Popup().setTitle(Messages.DELETE_REPORT_CONFIRM).addYesNoButtons(p -> {
|
event -> new Popup().setTitle(Messages.DELETE_REPORT_CONFIRM).addYesNoButtons(p -> {
|
||||||
reportDeleter.accept(report);
|
reportDeleter.accept(report);
|
||||||
getDataProvider().refreshAll();
|
getDataProvider().refreshAll();
|
||||||
}, true).show())));
|
}, true).show())));
|
||||||
|
|
80
src/main/java/com/faendir/acra/ui/component/CardDialog.java
Normal file
80
src/main/java/com/faendir/acra/ui/component/CardDialog.java
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
* (C) Copyright 2019 Lukas Morawietz (https://github.com/F43nd1r)
|
||||||
|
*
|
||||||
|
* Licensed 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.faendir.acra.ui.component;
|
||||||
|
|
||||||
|
import com.vaadin.flow.component.Component;
|
||||||
|
import com.vaadin.flow.component.dialog.Dialog;
|
||||||
|
import com.vaadin.flow.component.html.Div;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lukas
|
||||||
|
* @since 24.04.19
|
||||||
|
*/
|
||||||
|
public class CardDialog extends Dialog implements HasSize, HasStyle {
|
||||||
|
private final Div header;
|
||||||
|
private final Div content;
|
||||||
|
|
||||||
|
public CardDialog() {
|
||||||
|
header = new Div();
|
||||||
|
header.getStyle().set("padding", "1rem");
|
||||||
|
header.getStyle().set("box-sizing", "border-box");
|
||||||
|
header.getStyle().set("background-color", "var(--lumo-contrast-5pct)");
|
||||||
|
header.getStyle().set("display", "inline-block");
|
||||||
|
header.setWidth("100%");
|
||||||
|
content = new Div();
|
||||||
|
content.getStyle().set("padding", "1rem");
|
||||||
|
content.getStyle().set("box-sizing", "border-box");
|
||||||
|
content.getStyle().set("display", "inline-block");
|
||||||
|
content.setSizeFull();
|
||||||
|
super.add(header, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CardDialog(Component... components) {
|
||||||
|
this();
|
||||||
|
add(components);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAll() {
|
||||||
|
content.removeAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addComponentAtIndex(int index, Component component) {
|
||||||
|
content.addComponentAtIndex(index, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addComponentAsFirst(Component component) {
|
||||||
|
content.addComponentAsFirst(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Component... components) {
|
||||||
|
content.add(components);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Component... components) {
|
||||||
|
content.remove(components);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeader(Component... components) {
|
||||||
|
header.removeAll();
|
||||||
|
header.add(components);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeaderColor(String textColor, String backgroundColor) {
|
||||||
|
header.getStyle().set("color",textColor);
|
||||||
|
header.getStyle().set("background-color", backgroundColor);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* (C) Copyright 2019 Lukas Morawietz (https://github.com/F43nd1r)
|
||||||
|
*
|
||||||
|
* Licensed 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.faendir.acra.ui.component;
|
||||||
|
|
||||||
|
import com.faendir.acra.i18n.Messages;
|
||||||
|
import com.faendir.acra.model.App;
|
||||||
|
import com.faendir.acra.model.Version;
|
||||||
|
import com.faendir.acra.service.DataService;
|
||||||
|
import com.vaadin.flow.component.button.Button;
|
||||||
|
import com.vaadin.flow.component.textfield.NumberField;
|
||||||
|
import com.vaadin.flow.component.textfield.TextField;
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lukas
|
||||||
|
* @since 24.04.19
|
||||||
|
*/
|
||||||
|
public class VersionEditorDialog extends CardDialog {
|
||||||
|
public VersionEditorDialog(@NonNull DataService dataService, @NonNull App app, @Nullable Runnable onUpdate, @Nullable Version old) {
|
||||||
|
boolean isNew = old == null;
|
||||||
|
setHeader(Translatable.createText(isNew ? Messages.NEW_VERSION : Messages.EDIT_VERSION));
|
||||||
|
Translatable.Value<NumberField, Double> code = Translatable.createNumberField(isNew ? dataService.getMaxVersion(app).map(i -> i + 1d).orElse(1d) : old.getCode(), Messages.VERSION_CODE).with(n -> {
|
||||||
|
n.setStep(1d);
|
||||||
|
n.setMin(1d);
|
||||||
|
n.setPreventInvalidInput(true);
|
||||||
|
n.setHasControls(true);
|
||||||
|
n.setWidthFull();
|
||||||
|
if (!isNew) {
|
||||||
|
n.setEnabled(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Translatable.Value<TextField, String> name = Translatable.createTextField(isNew ? "" : old.getName(), Messages.VERSION_NAME).with(n -> {
|
||||||
|
if (isNew) {
|
||||||
|
n.setRequired(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Translatable.Value<UploadField, String> upload = Translatable.createUploadField(Messages.MAPPING_FILE).with(n -> {
|
||||||
|
n.setWidthFull();
|
||||||
|
if(!isNew) {
|
||||||
|
n.setValue(old.getMappings());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Translatable<Button> button = Translatable.createButton(e -> {
|
||||||
|
if(isNew) {
|
||||||
|
dataService.store(new Version(app, code.getValue().intValue(), name.getValue(), upload.getValue()));
|
||||||
|
} else {
|
||||||
|
old.setName(name.getValue());
|
||||||
|
old.setMappings(upload.getValue());
|
||||||
|
dataService.store(old);
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
if(onUpdate != null) {
|
||||||
|
onUpdate.run();
|
||||||
|
}
|
||||||
|
}, isNew ? Messages.CREATE : Messages.SAVE);
|
||||||
|
FlexLayout layout = new FlexLayout(code, name, upload, button);
|
||||||
|
layout.setFlexDirection(FlexLayout.FlexDirection.COLUMN);
|
||||||
|
add(layout);
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,7 +37,7 @@ import com.faendir.acra.ui.component.FlexLayout;
|
||||||
import com.faendir.acra.ui.component.HasSize;
|
import com.faendir.acra.ui.component.HasSize;
|
||||||
import com.faendir.acra.ui.component.RangeInput;
|
import com.faendir.acra.ui.component.RangeInput;
|
||||||
import com.faendir.acra.ui.component.Translatable;
|
import com.faendir.acra.ui.component.Translatable;
|
||||||
import com.faendir.acra.ui.component.UploadField;
|
import com.faendir.acra.ui.component.VersionEditorDialog;
|
||||||
import com.faendir.acra.ui.view.Overview;
|
import com.faendir.acra.ui.view.Overview;
|
||||||
import com.faendir.acra.ui.view.app.AppView;
|
import com.faendir.acra.ui.view.app.AppView;
|
||||||
import com.querydsl.core.types.dsl.BooleanExpression;
|
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||||
|
@ -51,8 +51,8 @@ import com.vaadin.flow.component.icon.Icon;
|
||||||
import com.vaadin.flow.component.icon.VaadinIcon;
|
import com.vaadin.flow.component.icon.VaadinIcon;
|
||||||
import com.vaadin.flow.component.orderedlayout.FlexComponent;
|
import com.vaadin.flow.component.orderedlayout.FlexComponent;
|
||||||
import com.vaadin.flow.component.textfield.NumberField;
|
import com.vaadin.flow.component.textfield.NumberField;
|
||||||
import com.vaadin.flow.component.textfield.TextField;
|
|
||||||
import com.vaadin.flow.data.renderer.ComponentRenderer;
|
import com.vaadin.flow.data.renderer.ComponentRenderer;
|
||||||
|
import com.vaadin.flow.data.renderer.IconRenderer;
|
||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
import com.vaadin.flow.server.StreamResource;
|
import com.vaadin.flow.server.StreamResource;
|
||||||
import com.vaadin.flow.spring.annotation.SpringComponent;
|
import com.vaadin.flow.spring.annotation.SpringComponent;
|
||||||
|
@ -96,42 +96,22 @@ public class AdminTab extends AppTab<Div> {
|
||||||
layout.removeAll();
|
layout.removeAll();
|
||||||
MyGrid<Version> versionGrid = new MyGrid<>(getDataService().getVersionProvider(app));
|
MyGrid<Version> versionGrid = new MyGrid<>(getDataService().getVersionProvider(app));
|
||||||
versionGrid.setHeightToRows();
|
versionGrid.setHeightToRows();
|
||||||
|
versionGrid.setHeight("");
|
||||||
versionGrid.addColumn(Version::getCode, QVersion.version.code, Messages.VERSION_CODE).setFlexGrow(1);
|
versionGrid.addColumn(Version::getCode, QVersion.version.code, Messages.VERSION_CODE).setFlexGrow(1);
|
||||||
versionGrid.addColumn(Version::getName, QVersion.version.name, Messages.VERSION).setFlexGrow(1);
|
versionGrid.addColumn(Version::getName, QVersion.version.name, Messages.VERSION).setFlexGrow(1);
|
||||||
versionGrid.setHeight("");
|
versionGrid.addColumn(new IconRenderer<>(v -> new Icon(v.getMappings() != null ? VaadinIcon.CHECK : VaadinIcon.CLOSE), v -> ""), QVersion.version.mappings.isNotNull(), Messages.PROGUARD_MAPPINGS);
|
||||||
Card versionCard = createCard(versionGrid);
|
|
||||||
versionCard.setHeader(Translatable.createText(Messages.VERSIONS));
|
|
||||||
if (SecurityUtils.hasPermission(app, Permission.Level.EDIT)) {
|
if (SecurityUtils.hasPermission(app, Permission.Level.EDIT)) {
|
||||||
versionGrid.addColumn(new ComponentRenderer<>(v -> new Button(new Icon(VaadinIcon.TRASH), e -> new Popup().addComponent(Translatable.createText(Messages.DELETE_MAPPING_CONFIRM, v.getCode())).addYesNoButtons(p -> {
|
versionGrid.addColumn(new ComponentRenderer<>(v -> new Button(new Icon(VaadinIcon.EDIT), e -> new VersionEditorDialog(getDataService(), app, () -> versionGrid.getDataProvider().refreshAll(), v).open())));
|
||||||
|
versionGrid.addColumn(new ComponentRenderer<>(v -> new Button(new Icon(VaadinIcon.TRASH), e -> new Popup().addComponent(Translatable.createText(Messages.DELETE_VERSION_CONFIRM, v.getCode())).addYesNoButtons(p -> {
|
||||||
getDataService().delete(v);
|
getDataService().delete(v);
|
||||||
versionGrid.getDataProvider().refreshAll();
|
versionGrid.getDataProvider().refreshAll();
|
||||||
}, true).show())));
|
}, true).show())));
|
||||||
versionGrid.appendFooterRow().getCell(versionGrid.getColumns().get(0)).setComponent(Translatable.createButton(e -> {
|
versionGrid.appendFooterRow().getCell(versionGrid.getColumns().get(0)).setComponent(Translatable.createButton(e -> new VersionEditorDialog(getDataService(), app, () -> versionGrid.getDataProvider().refreshAll(), null).open(), Messages.NEW_VERSION));
|
||||||
Translatable.Value<TextField, String> name = Translatable.createTextField("", Messages.VERSION_NAME);
|
|
||||||
name.getContent().setRequired(true);
|
|
||||||
Translatable.Value<NumberField, Double> version = Translatable.createNumberField(getDataService().getMaxVersion(app).map(i -> i + 1d).orElse(1d), Messages.VERSION_CODE)
|
|
||||||
.with(n -> {
|
|
||||||
n.setStep(1d);
|
|
||||||
n.setMin(1d);
|
|
||||||
n.setPreventInvalidInput(true);
|
|
||||||
n.setHasControls(true);
|
|
||||||
});
|
|
||||||
Translatable.Value<UploadField, String> upload = Translatable.createUploadField(Messages.MAPPING_FILE);
|
|
||||||
new Popup().setTitle(Messages.NEW_VERSION)
|
|
||||||
.addComponent(name)
|
|
||||||
.addComponent(version)
|
|
||||||
.addComponent(upload)
|
|
||||||
.addCreateButton(popup -> {
|
|
||||||
try {
|
|
||||||
getDataService().store(new Version(app, version.getValue().intValue(), name.getValue(), upload.getValue()));
|
|
||||||
} catch (Exception ex) {
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
versionGrid.getDataProvider().refreshAll();
|
|
||||||
}, true).show();
|
|
||||||
}, Messages.NEW_VERSION));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Card versionCard = createCard(versionGrid);
|
||||||
|
versionCard.setHeader(Translatable.createText(Messages.VERSIONS));
|
||||||
|
|
||||||
CssGrid notificationLayout = new CssGrid();
|
CssGrid notificationLayout = new CssGrid();
|
||||||
notificationLayout.setTemplateColumns("auto max-content");
|
notificationLayout.setTemplateColumns("auto max-content");
|
||||||
notificationLayout.setWidthFull();
|
notificationLayout.setWidthFull();
|
||||||
|
|
|
@ -22,6 +22,7 @@ acra.user.name=admin
|
||||||
acra.user.password=admin
|
acra.user.password=admin
|
||||||
acra.pagination-size=64
|
acra.pagination-size=64
|
||||||
vaadin.servlet.productionMode=true
|
vaadin.servlet.productionMode=true
|
||||||
|
spring.servlet.multipart.enabled=false
|
||||||
# spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata
|
# spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata
|
||||||
# spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
|
# spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
|
||||||
# spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=create.sql
|
# spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=create.sql
|
|
@ -158,4 +158,7 @@ welcome=Willkommen zu
|
||||||
createAdmin=Zuerst müssen Sie einen Adminstrator anlegen:
|
createAdmin=Zuerst müssen Sie einen Adminstrator anlegen:
|
||||||
notSolved=Nicht gelöst
|
notSolved=Nicht gelöst
|
||||||
versionName=Versionsname
|
versionName=Versionsname
|
||||||
reportFrom=Bericht vom %s
|
reportFrom=Bericht vom %s
|
||||||
|
deleteVersionConfirm=Sind Sie sicher dass Sie diese Version löschen wollen?
|
||||||
|
editVersion=Version bearbeiten
|
||||||
|
proguardMappings=Proguard map
|
|
@ -158,4 +158,7 @@ welcome=Welcome to
|
||||||
createAdmin=First, you have to create an administrator:
|
createAdmin=First, you have to create an administrator:
|
||||||
notSolved=Not solved
|
notSolved=Not solved
|
||||||
versionName=Version name
|
versionName=Version name
|
||||||
reportFrom=Report from %s
|
reportFrom=Report from %s
|
||||||
|
deleteVersionConfirm=Are you sure you want to delete this version?
|
||||||
|
editVersion=Edit Version
|
||||||
|
proguardMappings=Proguard mappings
|
Loading…
Reference in a new issue