--- /dev/null
+/*****************************************************************************
+ * Copyright Igor Barma, Eric Brun, Alexandre Desoubeaux, Christian Martel,
+ * (2 décembre 2008)
+ *
+ * Ce logiciel est un programme informatique servant à l'évaluation des
+ * compétences.
+ *
+ * Ce logiciel est régi par la licence CeCILL soumise au droit français et
+ * respectant les principes de diffusion des logiciels libres. Vous pouvez
+ * utiliser, modifier et/ou redistribuer ce programme sous les conditions
+ * de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
+ * sur le site "http://www.cecill.info".
+ *
+ * En contrepartie de l'accessibilité au code source et des droits de copie,
+ * de modification et de redistribution accordés par cette licence, il n'est
+ * offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
+ * seule une responsabilité restreinte pèse sur l'auteur du programme, le
+ * titulaire des droits patrimoniaux et les concédants successifs.
+ *
+ * A cet égard l'attention de l'utilisateur est attirée sur les risques
+ * associés au chargement, à l'utilisation, à la modification et/ou au
+ * développement et à la reproduction du logiciel par l'utilisateur étant
+ * donné sa spécificité de logiciel libre, qui peut le rendre complexe à
+ * manipuler et qui le réserve donc à des développeurs et des professionnels
+ * avertis possédant des connaissances informatiques approfondies. Les
+ * utilisateurs sont donc invités à charger et tester l'adéquation du
+ * logiciel à leurs besoins dans des conditions permettant d'assurer la
+ * sécurité de leurs systèmes et ou de leurs données et, plus généralement,
+ * à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
+ *
+ * Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
+ * pris connaissance de la licence CeCILL, et que vous en avez accepté les
+ * termes.
+ *******************************************************************************/
+package com.pentila.evalcomp.client.dashboard;
+
+import java.util.Map;
+import java.util.Set;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import com.gwtext.client.data.ArrayReader;
+import com.gwtext.client.data.FieldDef;
+import com.gwtext.client.data.IntegerFieldDef;
+import com.gwtext.client.data.MemoryProxy;
+import com.gwtext.client.data.Record;
+import com.gwtext.client.data.RecordDef;
+import com.gwtext.client.data.Store;
+import com.gwtext.client.data.StringFieldDef;
+import com.gwtext.client.widgets.form.FieldSet;
+import com.gwtext.client.widgets.form.NumberField;
+import com.gwtext.client.widgets.form.TextField;
+import com.gwtext.client.widgets.grid.CellMetadata;
+import com.gwtext.client.widgets.grid.ColumnConfig;
+import com.gwtext.client.widgets.grid.ColumnModel;
+import com.gwtext.client.widgets.grid.EditorGridPanel;
+import com.gwtext.client.widgets.grid.Renderer;
+import com.pentila.evalcomp.client.ConnexionServer;
+import com.pentila.evalcomp.client.i18n.Messages;
+import com.pentila.evalcomp.client.utilities.Tools;
+import com.pentila.evalcomp.domain.User;
+import com.pentila.evalcomp.domain.transit.TCompetence;
+import com.pentila.evalcomp.domain.transit.TReferentiel;
+import com.rednels.ofcgwt.client.ChartWidget;
+import com.rednels.ofcgwt.client.model.ChartData;
+import com.rednels.ofcgwt.client.model.elements.PieChart;
+
+
+/**
+ * The Class OFCUserDashboardFieldSet. GUI part that show an user stats chart
+ */
+public class OFCUserDashboardFieldSet extends FieldSet {
+
+ /** The content. */
+ private VerticalPanel content;
+
+ /**
+ * Instantiates a new oFC user dashboard field set.
+ *
+ * @param tref
+ * the referentiel on which we want stats
+ * @param user
+ * the user on which we want stats
+ * @param ownDashboard
+ * Set if the user is looking is own dashborad or not
+ */
+ public OFCUserDashboardFieldSet(TReferentiel tref, User user,
+ boolean ownDashboard) {
+ super();
+
+ if (ownDashboard) {
+ this.setTitle(Messages.getString("Vos_resultats"));
+ } else {
+ this.setTitle(Messages.getString("Resultats_du_candidat"));
+ }
+
+ this.setIconCls("iconUser16");
+
+ content = new VerticalPanel();
+ content.setSpacing(5);
+
+ this.add(content);
+
+ this.initializeTReferentiel(tref, user);
+ }
+
+ /**
+ * Get the stats data from instance manager.
+ *
+ * @param tref
+ * the referentiel on which we want stats
+ * @param user
+ * the user on which we want stats
+ */
+ private void initializeTReferentiel(TReferentiel tref, User user) {
+
+ AsyncCallback callback = new AsyncCallback() {
+ public void onFailure(Throwable caught) {
+ System.out.println("Probleme dans la maj des eval Folder");
+ }
+
+ public void onSuccess(Object result) {
+ TReferentiel tref = (TReferentiel) result;
+ initializeUserResults(tref);
+ }
+ };
+ ConnexionServer.instanceService.getUserReferentielStates(user.getUid(),
+ tref.getId(), callback);
+ }
+
+ /**
+ * Initialize user results GUI, chart and legend from stats data.
+ *
+ * @param tref
+ * the referentiel on which we want stats Used keys are
+ * "validable" and "nonvalidable".
+ */
+ private void initializeUserResults(TReferentiel tref) {
+
+
+ Map<String, Set<TCompetence>> m = tref.getCompetencesValidability();
+
+ Set<TCompetence> valid = m.get("validable");
+ Set<TCompetence> nonvalid = m.get("nonvalidable");
+
+ Float validF = ((Integer) valid.size()).floatValue();
+ Float nonValidF = ((Integer) nonvalid.size()).floatValue();
+
+ Integer tmpVal = (int) (((validF * new Float(100)) / (validF + nonValidF)) * new Float(
+ 100));
+
+ validF = (tmpVal.floatValue() / 100);
+
+ nonValidF = 100 - validF;
+
+ Object[][] objList = new Object[][] {
+ new Object[] {
+ "validables", "" + validF + "%", valid.size(), Messages.getString("couleur_OFC_validables") },
+ new Object[] {
+ "non validables", "" + nonValidF + "%", nonvalid.size(), Messages.getString("couleur_OFC_nonvalidables") }, };
+
+ MemoryProxy proxy = new MemoryProxy(objList);
+ RecordDef recordDef = new RecordDef(new FieldDef[] {
+ new StringFieldDef("competence"),
+ new StringFieldDef("percent"),
+ new IntegerFieldDef("nombre"), new StringFieldDef("legend") });
+
+ ArrayReader reader = new ArrayReader(recordDef);
+ final Store store = new Store(proxy, reader);
+ store.load();
+
+ ChartWidget chart = new ChartWidget();
+ String swfurl = Tools.getBaseURL() + "ofcgwt/open-flash-chart.swf";
+ chart.setFlashUrl("");
+ chart.setUrlPrefix(swfurl);
+ chart.setCacheFixEnabled(true);
+
+ ChartData cd = new ChartData();
+ cd.setBackgroundColour("#ffffff");
+ PieChart pie = new PieChart();
+ pie.setAlpha(0.3f);
+ pie.setNoLabels(true);
+ pie.setTooltip("#label#: #val#<br>#percent#");
+ pie.setAnimateOnShow(true);
+ pie.setGradientFill(true);
+ pie.setColours(
+ Messages.getString("couleur_OFC_validables"), Messages.getString("couleur_OFC_nonvalidables"));
+ pie.addSlices(new PieChart.Slice(valid.size(), Messages
+ .getString("Valides")));
+ pie.addSlices(new PieChart.Slice(nonvalid.size(), Messages
+ .getString("Non_valides")));
+ cd.addElements(pie);
+ chart.setSize("240", "240");
+ chart.setJsonData(cd.toString());
+
+
+ HorizontalPanel cbHpan = new HorizontalPanel();
+
+ cbHpan.setHeight("23px");
+ content.add(cbHpan);
+ content.add(chart);
+
+ ColumnConfig responseConfig = new ColumnConfig("",
+ "competence", 80, true);
+ TextField textField = new TextField();
+ textField.setSelectOnFocus(true);
+
+
+ NumberField numberField = new NumberField();
+ numberField.setSelectOnFocus(true);
+
+ ColumnConfig countConfig = new ColumnConfig(
+ Messages.getString("Competences"), "nombre", 80,
+ true);
+ ColumnConfig percentConfig = new ColumnConfig(" %", "percent", 50,
+ true);
+
+
+ ColumnConfig legendConfig = new ColumnConfig(" ", "legend", 5, true);
+ legendConfig.setRenderer(new Renderer() {
+ public String render(Object value, CellMetadata cellMetadata,
+ Record record, int rowIndex, int colNum, Store store) {
+ cellMetadata.setHtmlAttribute("style=\"background:" + value
+ + ";\"");
+ return "";
+ }
+ });
+
+ ColumnModel columnModel = new ColumnModel(new ColumnConfig[] {
+ responseConfig, countConfig, percentConfig, legendConfig });
+
+ EditorGridPanel grid = new EditorGridPanel();
+ grid.setStore(store);
+ grid.setColumnModel(columnModel);
+ grid.setWidth(225);
+ grid.setEnableColumnHide(false);
+ grid.setEnableColumnMove(false);
+ grid.setEnableColumnResize(false);
+
+ content.add(grid);
+
+ }
+
+}