package ee.pardiralli.util;

import ee.pardiralli.feedback.Feedback;
import ee.pardiralli.feedback.FeedbackType;
import org.springframework.ui.Model;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.List;

public class ControllerUtil {

    public static Model setFeedback(Model model, FeedbackType type, String feedback) {
        if (model.containsAttribute(Feedback.FEEDBACK_VARIABLE_NAME)) {
            List<Feedback> feedbacks = (List<Feedback>) model.asMap().get(Feedback.FEEDBACK_VARIABLE_NAME);
            feedbacks.add(new Feedback(feedback, type));
            model.addAttribute(Feedback.FEEDBACK_VARIABLE_NAME, feedbacks);
        } else {
            model.addAttribute(Feedback.FEEDBACK_VARIABLE_NAME, Collections.singletonList(new Feedback(feedback, type)));
        }
        return model;
    }

    public static String currentDatetime() {
        String dateTime = ZonedDateTime.now(ZoneId.of("Europe/Helsinki"))
                .truncatedTo(ChronoUnit.MINUTES)
                .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
        return dateTime.substring(0, dateTime.lastIndexOf(":")) + dateTime.substring(dateTime.lastIndexOf(":") + 1, dateTime.length());
    }
}

@@ -299,27 +299,25 @@
 va.util.
-Collections
+ArrayList
 ;%0Aimport
@@ -365,16 +365,590 @@
 Util %7B%0A%0A
+    /**%0A     * Adds feedback list to model. This can be later used via Thymeleaf to generate Bootstrap alert dialogs.%0A     * %3Cp%3E%0A     * For example %3Ccode%3EControllerUtil.setFeedback(FeedbackType.SUCCESS, %22Hello world!%22)%3C/code%3E will add a list%0A     * containing one %7B@link Feedback%7D object that can be used to generate%0A     * HTML tag %3Ccode%3E%3Cdiv class=%22alert alert-success%22%3EHello world!%3C/div%3E%3C/code%3E%0A     * %3Cp%3E%0A     *%0A     * @param model    to add feedback%0A     * @param type     of the feedback%0A     * @param feedback as message%0A     * @return model which is updated%0A     */%0A
     publ
@@ -1356,16 +1356,119 @@
  else %7B%0A
+            List%3CFeedback%3E lst = new ArrayList%3C%3E();%0A            lst.add(new Feedback(feedback, type));%0A
         
@@ -1527,63 +1527,11 @@
 ME, 
-Collections.singletonList(new Feedback(feedback, type))
+lst
 );%0A 

Fix feedback issue closes #140