Search in sources :

Example 1 with Item

use of io.bssw.psip.backend.data.Item in project psip-automation by bssw-psip.

the class Assessment method generateSaveUrl.

/**
 * Generate a url that can be used to resume assessment
 * @param activity
 * @return url
 */
private String generateSaveUrl(Activity activity) {
    StringBuilder query = new StringBuilder();
    Iterator<Category> categoryIter = activity.getCategories().iterator();
    while (categoryIter.hasNext()) {
        Category category = categoryIter.next();
        query.append(category.getPath() + "=");
        StringBuilder nested = new StringBuilder();
        Iterator<Item> itemIter = category.getItems().iterator();
        while (itemIter.hasNext()) {
            Item item = itemIter.next();
            nested.append(item.getPath() + ":" + item.getScore().orElse(0));
            if (itemIter.hasNext()) {
                nested.append("+");
            }
        }
        query.append(nested.toString());
        if (categoryIter.hasNext()) {
            query.append("&");
        }
    }
    return getLocation() + RouteConfiguration.forSessionScope().getUrl(Assessment.class, "?" + query.toString());
}
Also used : ScoreItem(io.bssw.psip.ui.components.ScoreItem) FormItem(com.vaadin.flow.component.formlayout.FormLayout.FormItem) Item(io.bssw.psip.backend.data.Item) Category(io.bssw.psip.backend.data.Category)

Example 2 with Item

use of io.bssw.psip.backend.data.Item in project psip-automation by bssw-psip.

the class Assessment method createItemLayout.

private void createItemLayout(Item item) {
    mainLayout.removeAll();
    ScoreItem scoreItem = new ScoreItem(item);
    String path = item.getCategory().getActivity().getPath() + "/" + item.getCategory().getPath() + "/" + item.getPath();
    Item prevItem = activityService.getPrevItem(path);
    Button button1 = UIUtils.createLargeButton(VaadinIcon.CHEVRON_CIRCLE_LEFT);
    // FIXME: Don't hard code background
    button1.getElement().getStyle().set("background", "#F3F5F7").set("font-size", "30px");
    button1.getElement().addEventListener("click", e -> {
        MainLayout.navigate(Assessment.class, prevItem.getCategory().getPath() + "/" + prevItem.getPath());
    });
    if (prevItem == null) {
        button1.getElement().setEnabled(false);
    }
    Item nextItem = activityService.getNextItem(path);
    Button button2 = UIUtils.createLargeButton(VaadinIcon.CHEVRON_CIRCLE_RIGHT);
    // FIXME: Don't hard code background
    button2.getElement().getStyle().set("background", "#F3F5F7").set("font-size", "30px");
    button2.getElement().addEventListener("click", e -> {
        MainLayout.navigate(Assessment.class, nextItem.getCategory().getPath() + "/" + nextItem.getPath());
    });
    if (nextItem == null) {
        button2.getElement().setEnabled(false);
    }
    HorizontalLayout hz = new HorizontalLayout(button1, button2);
    hz.setJustifyContentMode(JustifyContentMode.CENTER);
    hz.setWidthFull();
    Anchor anchor = new Anchor();
    anchor.setText("Show me my assessment");
    anchor.getElement().addEventListener("click", e -> MainLayout.navigate(Assessment.class, null));
    HorizontalLayout hz2 = new HorizontalLayout(anchor);
    hz2.setJustifyContentMode(JustifyContentMode.CENTER);
    hz2.setWidthFull();
    VerticalLayout footer = new VerticalLayout(hz, hz2);
    footer.setMargin(false);
    mainLayout.addAndExpand(scoreItem, footer);
}
Also used : ScoreItem(io.bssw.psip.ui.components.ScoreItem) FormItem(com.vaadin.flow.component.formlayout.FormLayout.FormItem) Item(io.bssw.psip.backend.data.Item) Anchor(com.vaadin.flow.component.html.Anchor) Button(com.vaadin.flow.component.button.Button) ScoreItem(io.bssw.psip.ui.components.ScoreItem) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 3 with Item

use of io.bssw.psip.backend.data.Item in project psip-automation by bssw-psip.

the class Assessment method setParameter.

@Override
public void setParameter(BeforeEvent event, @WildcardParameter String parameter) {
    String desc = "";
    if (parameter.isEmpty()) {
        Activity activity = activityService.getActivity("Assessment");
        desc = activity.getDescription();
        // Get query parameters and restore state if there are any
        Location location = event.getLocation();
        QueryParameters queryParameters = location.getQueryParameters();
        Map<String, List<String>> parametersMap = queryParameters.getParameters();
        if (!parametersMap.isEmpty()) {
            restoreSaveUrl(activity, parametersMap);
        }
        createActivityLayout(activity);
    } else if (parameter.contains("/")) {
        // Item
        Item item = activityService.getItem("assessment/" + parameter);
        if (item != null) {
            desc = item.getDescription();
            createItemLayout(item);
        } else {
            System.out.println("invalid parameter=" + parameter);
        }
    } else {
        // Category
        Category category = activityService.getCategory("assessment/" + parameter);
        desc = category.getDescription();
        createCategoryLayout(category);
    }
    description.getElement().setText(desc);
}
Also used : ScoreItem(io.bssw.psip.ui.components.ScoreItem) FormItem(com.vaadin.flow.component.formlayout.FormLayout.FormItem) Item(io.bssw.psip.backend.data.Item) Category(io.bssw.psip.backend.data.Category) Activity(io.bssw.psip.backend.data.Activity) List(java.util.List) QueryParameters(com.vaadin.flow.router.QueryParameters) Location(com.vaadin.flow.router.Location)

Example 4 with Item

use of io.bssw.psip.backend.data.Item in project psip-automation by bssw-psip.

the class Assessment method createActivitySummaryAsProgress.

@SuppressWarnings("unused")
private Component createActivitySummaryAsProgress(Activity activity) {
    FormLayout form = new FormLayout();
    for (Category category : activity.getCategories()) {
        int score = 0;
        for (Item item : category.getItems()) {
            if (item.getScore().isPresent()) {
                score += item.getScore().get();
            }
        }
        ProgressBar bar = new ProgressBar(0, category.getItems().size() > 0 ? 100 * category.getItems().size() : 1);
        bar.getElement().getStyle().set("height", "10px");
        bar.setValue(score);
        if (category.getItems().isEmpty()) {
            bar.getElement().setEnabled(false);
        }
        FormItem formItem = form.addFormItem(bar, category.getName());
        // Set width of label otherwise it will wrap
        formItem.getElement().getStyle().set("--vaadin-form-item-label-width", "15em");
        // FormLayout defaults to 2 columns so span both
        form.setColspan(formItem, 2);
    }
    return form;
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) ScoreItem(io.bssw.psip.ui.components.ScoreItem) FormItem(com.vaadin.flow.component.formlayout.FormLayout.FormItem) Item(io.bssw.psip.backend.data.Item) Category(io.bssw.psip.backend.data.Category) FormItem(com.vaadin.flow.component.formlayout.FormLayout.FormItem) ProgressBar(com.vaadin.flow.component.progressbar.ProgressBar)

Example 5 with Item

use of io.bssw.psip.backend.data.Item in project psip-automation by bssw-psip.

the class GenData method run.

public void run(String input, Optional<String> output) throws IOException {
    Yaml yaml = new Yaml(new Constructor(Content.class));
    InputStream inputStream = FileUtils.openInputStream(new File(input));
    Content content = yaml.load(inputStream);
    if (output.isPresent()) {
        BufferedWriter bw = Files.newBufferedWriter(Paths.get(output.get()));
        PrintWriter writer = new PrintWriter(bw);
        int activity_id = 1;
        for (Activity activity : content.getActivities()) {
            writer.println("insert into activity (id, name, icon, path, description) values (" + activity_id++ + ", '" + activity.getName() + "', '" + activity.getIcon() + "', '" + activity.getPath() + "', '" + activity.getDescription() + "');");
        }
        writer.println("commit;");
        activity_id = 1;
        int score_id = 1;
        for (Activity activity : content.getActivities()) {
            for (Score score : activity.getScores()) {
                writer.println("insert into score (id, name, boost, value, color, activity_id) values (" + score_id++ + ", '" + score.getName() + "', '" + score.getBoost() + "', " + score.getValue() + ", '" + score.getColor() + "', " + activity_id + ");");
            }
            activity_id++;
        }
        writer.println("commit;");
        activity_id = 1;
        int category_id = 1;
        for (Activity activity : content.getActivities()) {
            for (Category category : activity.getCategories()) {
                writer.println("insert into category (id, name, activity_id, icon, path, description) values (" + category_id++ + ", '" + category.getName() + "', " + activity_id + ", '', '" + category.getPath() + "', '" + category.getDescription() + "');");
            }
            activity_id++;
        }
        writer.println("commit;");
        category_id = 1;
        int item_id = 1;
        for (Activity activity : content.getActivities()) {
            for (Category category : activity.getCategories()) {
                for (Item item : category.getItems()) {
                    writer.println("insert into item (id, name, category_id, icon, path, description) values (" + item_id++ + ", '" + item.getName() + "', " + category_id + ", '', '" + item.getPath() + "', '" + item.getDescription() + "');");
                }
                category_id++;
            }
        }
        writer.println("commit;");
        item_id = 1;
        for (Activity activity : content.getActivities()) {
            for (Category category : activity.getCategories()) {
                for (Item item : category.getItems()) {
                    for (String question : item.getQuestions()) {
                        writer.println("insert into item_questions (item_id, questions) values (" + item_id + ", '" + question + "');");
                    }
                    item_id++;
                }
            }
        }
        writer.println("commit;");
        writer.close();
    }
}
Also used : Category(io.bssw.psip.backend.data.Category) Constructor(org.yaml.snakeyaml.constructor.Constructor) InputStream(java.io.InputStream) Activity(io.bssw.psip.backend.data.Activity) Yaml(org.yaml.snakeyaml.Yaml) BufferedWriter(java.io.BufferedWriter) Item(io.bssw.psip.backend.data.Item) Score(io.bssw.psip.backend.data.Score) Content(io.bssw.psip.backend.data.Content) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

Item (io.bssw.psip.backend.data.Item)7 FormItem (com.vaadin.flow.component.formlayout.FormLayout.FormItem)5 Category (io.bssw.psip.backend.data.Category)5 ScoreItem (io.bssw.psip.ui.components.ScoreItem)5 Activity (io.bssw.psip.backend.data.Activity)3 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)2 Anchor (com.vaadin.flow.component.html.Anchor)2 Component (com.vaadin.flow.component.Component)1 Button (com.vaadin.flow.component.button.Button)1 Div (com.vaadin.flow.component.html.Div)1 Emphasis (com.vaadin.flow.component.html.Emphasis)1 Paragraph (com.vaadin.flow.component.html.Paragraph)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)1 ProgressBar (com.vaadin.flow.component.progressbar.ProgressBar)1 Location (com.vaadin.flow.router.Location)1 QueryParameters (com.vaadin.flow.router.QueryParameters)1 Content (io.bssw.psip.backend.data.Content)1 Score (io.bssw.psip.backend.data.Score)1 ScoreSlider (io.bssw.psip.ui.components.ScoreSlider)1