package com.dungeonstory.ui.view.admin.grid;

import com.dungeonstory.backend.data.Character;
import com.dungeonstory.backend.data.Level;
import com.dungeonstory.backend.service.Services;
import com.vaadin.ui.renderers.ProgressBarRenderer;

public class CharacterGrid
        extends DSGrid<Character> {

    private static final long serialVersionUID = 8060713315641761422L;

    public CharacterGrid() {
        super();

        addColumn(Character::getName).setCaption("Nom").setId("name");
        addColumn(character -> {
            Level previousLevel = Services.getLevelService().read(character.getLevel().getId() - 1);
            double progress = (double) (character.getExperience() - previousLevel.getMaxExperience())
                    / (double) (character.getLevel().getMaxExperience() - previousLevel.getMaxExperience());
            return progress;
        }, new ProgressBarRenderer()).setCaption("Progrès").setId("progress");

    }

}

@@ -669,16 +669,228 @@
 ogress =
+ 0.0;%0D%0A            if (previousLevel == null) %7B%0D%0A                progress = (double) character.getExperience() / (double) character.getLevel().getMaxExperience();%0D%0A            %7D else %7B%0D%0A                progress =
  (double
@@ -955,16 +955,20 @@
 nce())%0D%0A
+    
         
@@ -1065,24 +1065,39 @@
 rience());%0D%0A
+            %7D%0D%0A
             

fix character experience progress bar