Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Update #76: finalize Navigator Input Selection for User Action.
Browse files Browse the repository at this point in the history
Correct bugs with user notification page (regression).
Correct bugs with EntrySummary (regression).
  • Loading branch information
hdsdi3g committed Nov 16, 2014
1 parent c332e88 commit 1fd2d4c
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 61 deletions.
24 changes: 12 additions & 12 deletions app/controllers/UserNotifications.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,37 +75,37 @@ private static Notification getNotification(UserProfile user, String key, boolea
return null;
}
flash("error", Messages.all(play.i18n.Lang.get()).getProperty("userprofile.notifications.cantfoundselected"));
redirect("User.notificationslist");
redirect("UserNotifications.notificationslist");
}
if (notification.containsObserver(user) == false) {
if (doredirect == false) {
return null;
}
flash("error", Messages.all(play.i18n.Lang.get()).getProperty("userprofile.notifications.cantfoundvalid"));
redirect("User.notificationslist");
redirect("UserNotifications.notificationslist");
}
if (must_not_closed & notification.isClose()) {
flash("error", Messages.all(play.i18n.Lang.get()).getProperty("userprofile.notifications.isclosed"));
redirect("User.notificationslist");
redirect("UserNotifications.notificationslist");
}
return notification;
}

public static void notificationclose(@Required String key) throws Exception {
if (Validation.hasErrors()) {
redirect("User.notificationslist");
redirect("UserNotifications.notificationslist");
return;
}
flash("lastkey", key);

UserProfile user = User.getUserProfile();
getNotification(user, key, true, true).switchCloseStatus(user).save();
redirect("User.notificationslist");
redirect("UserNotifications.notificationslist");
}

public static void notificationupdatealert(@Required String key, @Required String reason, @Required Boolean notify) throws Exception {
if (Validation.hasErrors()) {
redirect("User.notificationslist");
redirect("UserNotifications.notificationslist");
return;
}
flash("lastkey", key);
Expand All @@ -114,23 +114,23 @@ public static void notificationupdatealert(@Required String key, @Required Strin
NotifyReason n_resaon = NotifyReason.getFromDbRecordName(reason);
if (n_resaon == null) {
flash("error", Messages.all(play.i18n.Lang.get()).getProperty("userprofile.notifications.invalidreason"));
redirect("User.notificationslist");
redirect("UserNotifications.notificationslist");
}

getNotification(user, key, true, true).updateNotifyReasonForUser(user, n_resaon, notify).save();
redirect("User.notificationslist");
redirect("UserNotifications.notificationslist");
}

public static void notificationupdatecomment(@Required String key, String comment) throws Exception {
if (Validation.hasErrors()) {
redirect("User.notificationslist");
redirect("UserNotifications.notificationslist");
return;
}
flash("lastkey", key);
UserProfile user = User.getUserProfile();

getNotification(user, key, true, true).updateComment(user, comment).save();
redirect("User.notificationslist");
redirect("UserNotifications.notificationslist");
}

public static void notificationupdateread(@Required String key) throws Exception {
Expand Down Expand Up @@ -215,7 +215,7 @@ public static void notificationsadminlist() throws Exception {
@Check("adminUsers")
public static void notificationadminclose(@Required String key) throws Exception {
if (Validation.hasErrors()) {
redirect("User.notificationsadminlist");
redirect("UserNotifications.notificationsadminlist");
return;
}
UserProfile user = User.getUserProfile();
Expand All @@ -226,7 +226,7 @@ public static void notificationadminclose(@Required String key) throws Exception
notification.switchCloseStatus(user).save();
}

redirect("User.notificationsadminlist");
redirect("UserNotifications.notificationsadminlist");
}

}
44 changes: 33 additions & 11 deletions app/hd3gtv/mydmam/db/orm/ORMFormField.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,30 @@
import hd3gtv.mydmam.db.orm.annotations.ReadOnly;
import hd3gtv.mydmam.db.orm.annotations.TypeEmail;
import hd3gtv.mydmam.db.orm.annotations.TypeLongText;
import hd3gtv.mydmam.db.orm.annotations.TypeNavigatorInputSelection;
import hd3gtv.mydmam.db.orm.annotations.TypePassword;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.persistence.Transient;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;

public class ORMFormField {

private static Gson gson = new Gson();
public static final Type TYPE_AL_FIELDS = new TypeToken<ArrayList<ORMFormField>>() {
}.getType();

ORMFormField() {
}

Expand All @@ -46,6 +56,7 @@ public class ORMFormField {
public boolean hidden;
public boolean readonly;
public String class_referer = null;
public Object options = null;

public String toString() {
StringBuffer sb = new StringBuffer();
Expand All @@ -62,6 +73,10 @@ public String toString() {
return sb.toString();
}

public static JsonElement getJsonFields(List<ORMFormField> fields) {
return gson.toJsonTree(fields, TYPE_AL_FIELDS);
}

/**
* Get usable fields for an user view.
*/
Expand Down Expand Up @@ -102,30 +117,37 @@ public static List<ORMFormField> getFields(Class<?> class_model) throws Security
continue;
}
} else {

if (CharSequence.class.isAssignableFrom(field.getType())) {
ormformfield.type = "text";
if (field.isAnnotationPresent(TypeLongText.class)) {
ormformfield.type = "longtext";
}
if (field.isAnnotationPresent(TypePassword.class)) {
} else if (field.isAnnotationPresent(TypePassword.class)) {
ormformfield.type = "password";
}
if (field.isAnnotationPresent(TypeEmail.class)) {
} else if (field.isAnnotationPresent(TypeEmail.class)) {
ormformfield.type = "email";
}
}
if (Number.class.isAssignableFrom(field.getType()) || field.getType().equals(double.class) || field.getType().equals(int.class) || field.getType().equals(long.class)) {
ormformfield.type = "number";
}
if (Boolean.class.isAssignableFrom(field.getType()) || field.getType().equals(boolean.class)) {
} else if (Boolean.class.isAssignableFrom(field.getType()) || field.getType().equals(boolean.class)) {
ormformfield.type = "boolean";
}
if (Date.class.isAssignableFrom(field.getType())) {
} else if (Date.class.isAssignableFrom(field.getType())) {
ormformfield.type = "date";
}
if (field.getType().isEnum()) {
} else if (field.getType().isEnum()) {
ormformfield.type = "enum";
} else if (field.isAnnotationPresent(TypeNavigatorInputSelection.class)) {
ormformfield.type = "navigatorinputselection";
TypeNavigatorInputSelection field_conf = field.getAnnotation(TypeNavigatorInputSelection.class);
HashMap<String, Object> conf = new HashMap<String, Object>(4);
conf.put("canselectdirs", field_conf.canselectdirs());
conf.put("canselectfiles", field_conf.canselectfiles());
conf.put("canselectstorages", field_conf.canselectstorages());
if (field_conf.placeholderlabel() != null) {
if (field_conf.placeholderlabel().equals("") == false) {
conf.put("placeholder", field_conf.placeholderlabel());
}
}
ormformfield.options = conf;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* This file is part of MyDMAM.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* Copyright (C) hdsdi3g for hd3g.tv 2014
*
*/
package hd3gtv.mydmam.db.orm.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Used in Useraction with navigator.inputselect.js
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD })
public @interface TypeNavigatorInputSelection {

boolean canselectfiles() default true;

boolean canselectdirs() default true;

boolean canselectstorages() default true;

/**
* It will be translated with i18n.
*/
String placeholderlabel() default "";

}
11 changes: 5 additions & 6 deletions app/hd3gtv/mydmam/metadata/container/EntrySummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -32,11 +31,11 @@

public final class EntrySummary extends Entry {

private LinkedHashMap<String, Preview> previews;
private HashMap<String, Preview> previews;
Map<String, String> summaries;
public boolean master_as_preview;
private String mimetype;
private transient LinkedHashMap<PreviewType, Preview> cache_previews;
private transient HashMap<PreviewType, Preview> cache_previews;

public final static String type = "summary";

Expand Down Expand Up @@ -138,10 +137,10 @@ public Map<String, String> getSummaries() {

private void populate_previews() {
if (previews == null) {
previews = new LinkedHashMap<String, Preview>(1);
previews = new HashMap<String, Preview>(1);
}
if (cache_previews == null) {
cache_previews = new LinkedHashMap<PreviewType, Preview>();
cache_previews = new HashMap<PreviewType, Preview>();
for (Map.Entry<String, Preview> entry : previews.entrySet()) {
cache_previews.put(PreviewType.valueOf(entry.getKey()), entry.getValue());
}
Expand Down Expand Up @@ -177,7 +176,7 @@ public Preview getPreview(PreviewType previewtype) {
/**
* Don't add or delete items from here.
*/
public LinkedHashMap<PreviewType, Preview> getPreviews() {
public HashMap<PreviewType, Preview> getPreviews() {
populate_previews();
return cache_previews;
}
Expand Down
7 changes: 2 additions & 5 deletions app/hd3gtv/mydmam/useraction/UAConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;

public final class UAConfigurator implements Log2Dumpable {

Expand All @@ -53,8 +52,7 @@ public Log2Dump getLog2Dump() {
dump.add("type", origin);
Gson gson = UAManager.getGson();
dump.add("object", gson.toJson(object));
dump.add("fields", gson.toJson(fields, new TypeToken<ArrayList<ORMFormField>>() {
}.getType()));
dump.add("fields", gson.toJson(fields, ORMFormField.TYPE_AL_FIELDS));
return dump;
}

Expand Down Expand Up @@ -103,8 +101,7 @@ public JsonElement serialize(UAConfigurator src, Type typeOfSrc, JsonSerializati
je.add("type", new JsonPrimitive(src.type));
je.add("origin", new JsonPrimitive(src.origin));
je.add("object", UAManager.getGson().toJsonTree(src.object));
je.add("fields", UAManager.getGson().toJsonTree(src.fields, new TypeToken<ArrayList<ORMFormField>>() {
}.getType()));
je.add("fields", ORMFormField.getJsonFields(src.fields));
return je;
}

Expand Down
8 changes: 8 additions & 0 deletions app/hd3gtv/mydmam/useraction/dummy/UADummyConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import hd3gtv.log2.Log2Dumpable;
import hd3gtv.mydmam.db.orm.annotations.TypeEmail;
import hd3gtv.mydmam.db.orm.annotations.TypeLongText;
import hd3gtv.mydmam.db.orm.annotations.TypeNavigatorInputSelection;
import hd3gtv.mydmam.db.orm.annotations.TypePassword;
import hd3gtv.mydmam.pathindexing.Explorer;

import java.io.Serializable;

Expand All @@ -39,13 +41,19 @@ public class UADummyConfigurator implements Serializable, Log2Dumpable {
@TypePassword
public String apassword;

@TypeNavigatorInputSelection(canselectdirs = false, canselectstorages = false)
public String path;

public Log2Dump getLog2Dump() {
Log2Dump dump = new Log2Dump();
dump.add("avalue", avalue);
dump.add("anumber", anumber);
dump.add("amail", amail);
dump.add("alongtext", alongtext);
dump.add("apassword", apassword);
Explorer ex = new Explorer();
dump.add("path", path);
dump.add("path file", ex.getelementByIdkey(path));
return dump;
}
}
5 changes: 3 additions & 2 deletions app/hd3gtv/mydmam/web/stat/Stat.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import hd3gtv.mydmam.pathindexing.SourcePathIndexerElement;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -212,8 +213,8 @@ private static Map<String, Map<String, Object>> getSummariesByContainers(Contain

Container c;
Map<String, String> summaries;
Map<String, Object> item;
LinkedHashMap<PreviewType, Preview> previews;
LinkedHashMap<String, Object> item;
HashMap<PreviewType, Preview> previews;
for (int pos = 0; pos < containers.size(); pos++) {
c = containers.getItemAtPos(pos);
if (c.getSummary().getSummaries().isEmpty()) {
Expand Down
9 changes: 9 additions & 0 deletions conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ browser.oneelement=1 element
browser.Nelements=%s elements
browser.goback=Go back
browser.loadingplayer=Loading the player...
browser.inputselect.loading=Loading...
browser.inputselect.errorduringloading=Error during loading !
browser.inputselect.cantfoundcurrentdir=Can't found current directory.
browser.inputselect.emptydirnoitems=Empty directory or no items to display.
browser.inputselect.toomanyitems=Too many items to display: enter text to search.
browser.inputselect.defaultplaceholder.filesdirs=Select a file or directory
browser.inputselect.defaultplaceholder.files=Select a file
browser.inputselect.defaultplaceholder.dirs=Select a directory
browser.inputselect.defaultplaceholder.storage=Select a storage

crud.title=Administration
crud.home=Home
Expand Down
9 changes: 9 additions & 0 deletions conf/messages.fr
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ browser.oneelement=1 élément
browser.Nelements=%s éléments
browser.goback=Retour
browser.loadingplayer=Chargement du lecteur...
browser.inputselect.loading=Chargement...
browser.inputselect.errorduringloading=Erreur pendant le chargement !
browser.inputselect.cantfoundcurrentdir=Impossible de trouver le dossier courant.
browser.inputselect.emptydirnoitems=Dossier vide ou aucun élément à afficher.
browser.inputselect.toomanyitems=Trop d'éléments à afficher: entrez un texte à rechercher
browser.inputselect.defaultplaceholder.filesdirs=Choisissez un fichier ou un dossier
browser.inputselect.defaultplaceholder.files=Choisissez un fichier
browser.inputselect.defaultplaceholder.dirs=Choisissez un dossier
browser.inputselect.defaultplaceholder.storage=Choisissez un stockage

crud.title=Administration
crud.home=Home
Expand Down
Loading

0 comments on commit 1fd2d4c

Please sign in to comment.