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

Commit

Permalink
Update task/jobs status displaying, publish task/job JSON status from…
Browse files Browse the repository at this point in the history
… selected keys, user can't do update on notification if it closed, for #43
  • Loading branch information
hdsdi3g committed May 14, 2014
1 parent 1bdc494 commit 83f77f2
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 42 deletions.
16 changes: 16 additions & 0 deletions app/controllers/Queue.java
Expand Up @@ -78,6 +78,22 @@ public static void getworkers() throws Exception {
renderJSON(jo.toJSONString());
}

/**
* Open for all users
*/
public static void gettasksjobs() throws Exception {
String[] tasksjobs_keys = params.getAll("tasksjobs_keys[]");
if (tasksjobs_keys == null) {
renderJSON("{}");
return;
}
if (tasksjobs_keys.length == 0) {
renderJSON("{}");
return;
}
renderJSON(Broker.getTasksAndJobsByKeys(tasksjobs_keys));
}

@Check("updateQueue")
public static void changeworkerstate(@Required String worker_ref, @Required String newstate) throws Exception {
JSONObject jo = new JSONObject();
Expand Down
38 changes: 13 additions & 25 deletions app/controllers/User.java
Expand Up @@ -24,7 +24,6 @@
import hd3gtv.mydmam.db.orm.annotations.PublishedMethod;
import hd3gtv.mydmam.mail.notification.Notification;
import hd3gtv.mydmam.mail.notification.NotifyReason;
import hd3gtv.mydmam.taskqueue.Broker;

import java.lang.reflect.Method;
import java.util.ArrayList;
Expand Down Expand Up @@ -221,14 +220,14 @@ private static UserProfile getUserProfile() throws Exception {
public static void notificationslist() throws Exception {
String title = Messages.all(play.i18n.Lang.get()).getProperty("userprofile.notifications.pagename");
UserProfile user = getUserProfile();
ArrayList<Map<String, Object>> user_notifications = Notification.getRawFromDatabaseByObserver(user, true);// XXX set to false
ArrayList<Map<String, Object>> user_notifications = Notification.getRawFromDatabaseByObserver(user, false);
render(title, user_notifications, user);
}

/**
* @return valid notification for user, or (flash error + redirect to list) | (or if doredirect: return null)
*/
private static Notification getNotification(UserProfile user, String key, boolean doredirect) throws Exception {
private static Notification getNotification(UserProfile user, String key, boolean doredirect, boolean must_not_closed) throws Exception {
Notification notification = Notification.getFromDatabase(key);

if (notification == null) {
Expand All @@ -245,19 +244,22 @@ private static Notification getNotification(UserProfile user, String key, boolea
flash("error", "Can't found valid notification for you");// TODO Messages.all(play.i18n.Lang.get()).getProperty("userprofile.notifications.")
redirect("User.notificationslist");
}

if (must_not_closed & notification.isClose()) {
flash("error", "Notification is closed");// TODO Messages.all(play.i18n.Lang.get()).getProperty("userprofile.notifications.")
redirect("User.notificationslist");
}
return notification;
}

public static void notificationclose(@Required String key) throws Exception {// TODO test me
public static void notificationclose(@Required String key) throws Exception {
if (validation.hasErrors()) {
redirect("User.notificationslist");
return;
}
flash("lastkey", key);

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

Expand All @@ -275,7 +277,7 @@ public static void notificationupdatealert(@Required String key, @Required Strin
redirect("User.notificationslist");
}

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

Expand All @@ -287,17 +289,17 @@ public static void notificationupdatecomment(@Required String key, String commen
flash("lastkey", key);
UserProfile user = getUserProfile();

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

public static void notificationupdateread(@Required String key) throws Exception {// TODO test me
public static void notificationupdateread(@Required String key) throws Exception {
if (validation.hasErrors()) {
error(new NullPointerException("Invalid key"));
}

UserProfile user = getUserProfile();
getNotification(user, key, false).switchReadStatus(user).save();
getNotification(user, key, false, true).switchReadStatus(user).save();
JSONObject jo = new JSONObject();
jo.put("result", true);
renderJSON(jo.toJSONString());
Expand Down Expand Up @@ -338,19 +340,5 @@ public static void notificationresolveusers() throws Exception {
renderJSON(jo.toJSONString());
}

public static void notificationresolvertasksjobs() throws Exception {
String[] tasksjobs_keys = params.getAll("tasksjobs_keys[]");
if (tasksjobs_keys == null) {
renderJSON("{}");
return;
}
if (tasksjobs_keys.length == 0) {
renderJSON("{}");
return;
}
renderJSON(Broker.getTasksAndJobsByKeys(tasksjobs_keys));
}

// TODO routes + publish URL for JS side + js side

// TODO translate all
}
4 changes: 4 additions & 0 deletions app/hd3gtv/mydmam/mail/notification/Notification.java
Expand Up @@ -385,6 +385,10 @@ public boolean containsObserver(UserProfile candidate) {
return observers.contains(candidate);
}

public boolean isClose() {
return is_close;
}

public Notification addLinkedTasksJobs(String... taskjobkey) throws ConnectionException {
LinkedHashMap<String, TaskJobStatus> all_actual_status = Broker.getStatusForTasksOrJobsByKeys(taskjobkey);
if (all_actual_status == null) {
Expand Down
4 changes: 2 additions & 2 deletions app/views/Queue/index.html
Expand Up @@ -38,9 +38,9 @@
var url_getall = "@{Queue.getall()}";
var url_getupdate = "@{Queue.getupdate()}";

var enable_update = false;
var enable_update_queue = false;
#{secure.check 'updateQueue'}
var enable_update = true;
var enable_update_queue = true;
url_changetaskstatus = "@{Queue.changetaskstatus()}";
url_changetaskpriority = "@{Queue.changetaskpriority()}";
url_changetaskmaxage = "@{Queue.changetaskmaxage()}";
Expand Down
10 changes: 7 additions & 3 deletions app/views/User/notificationslist.html
Expand Up @@ -41,7 +41,9 @@
<button class="btn btn-mini #{if notification.is_read == false}btnsetreadnotification#{/if}" data-target="#notificationcontent${pos}" data-toggle="collapse" data-notificationkey="${notification.key}">
<i class="icon-chevron-down"></i>
</button>
<span class="label label-info">&{notification.summary_status}</span>
<span class="redrawstatus" data-status="${notification.summary_status}">
<span class="label label-info">&{notification.summary_status}</span>
</span>
${notification.creating_comment}
</div>
<div class="collapse #{if flash.lastkey == notification.key}in#{/if}" id="notificationcontent${pos}">
Expand Down Expand Up @@ -138,7 +140,7 @@
<div id="tabpane${pos}tj" class="tab-pane">
<div class="row-fluid">
%{ notification.linked_tasks.eachWithIndex() { taskjob, tpos -> }%
<div class="taskjobsummary">${taskjob.taskjobkey}</div>
<div class="taskjobsummary" style="margin-left: 40px;" id="taskjobsummary${pos}-${tpos}">${taskjob.taskjobkey}</div>
%{ } }%
</div> <!-- row-fluid -->
</div> <!-- tab-pane -->
Expand All @@ -158,7 +160,9 @@
<script type="text/javascript" charset="UTF-8">
<!--
var url_notificationupdateread = "@{User.notificationupdateread(key='keyparam1')}";
var url_notificationresolveusers = "@{User.notificationresolveusers}"
var url_notificationresolveusers = "@{User.notificationresolveusers}";
var url_queuegettasksjobs = "@{Queue.gettasksjobs}";
var enable_update_queue = false;

$(document).ready(function() {
$("#btnSession").addClass("active");
Expand Down
2 changes: 2 additions & 0 deletions conf/messages.en
Expand Up @@ -254,6 +254,8 @@ userprofile.notifications.errorduringsetread=Error while changing the read statu
userprofile.notifications.emptylist=There not are currently notifications.
userprofile.notifications.errorduringgetusers=Error while get users names.
userprofile.notifications.unknown=Unknown
userprofile.notifications.cantfoundtaskjob=Deleted
userprofile.notifications.errorduringgettasksjobs=Error while get tasks and jobs item

crud.field.userprofile=User settings
crud.field.userprofile.longname=Name
Expand Down
2 changes: 2 additions & 0 deletions conf/messages.fr
Expand Up @@ -254,6 +254,8 @@ userprofile.notifications.errorduringsetread=Erreur pendant le changement de d'
userprofile.notifications.emptylist=Il n'y a plus de notifications en cours.
userprofile.notifications.errorduringgetusers=Erreur pendant le changement des noms d'utilisateur.
userprofile.notifications.unknown=Inconnu
userprofile.notifications.cantfoundtaskjob=Purgée
userprofile.notifications.errorduringgettasksjobs=Erreur pendant le changement de la liste des taches et jobs.

crud.field.userprofile=Préférences utilisateur
crud.field.userprofile.longname=Nom
Expand Down
95 changes: 91 additions & 4 deletions public/javascripts/src/mydmam.notification.js
Expand Up @@ -91,7 +91,7 @@
$.ajax({
url: url_notificationresolveusers,
type: "POST",
async: false,
async: true,
data: {
"users_crypted_keys": users_crypted_keys
},
Expand All @@ -111,17 +111,104 @@
* getAndDisplayTasksJobs
*/
(function(notification) {
notification.getAndDisplayTasksJobs = function() {
//TODO
//$(this).html('<span class="label label-inverse">' + key + '</span>');
notification.displayStatus = function(status) {
var clazz = "";
if (status === "WAITING") {
clazz = "badge-info";
} else if (status === "PREPARING") {
clazz = "badge-warning";
} else if (status === "PROCESSING") {
clazz = "badge-warning";
} else if (status === "POSTPONED") {
clazz = "badge-info";
} else if (status === "STOPPED") {
clazz = "badge-inverse";
} else if (status === "CANCELED") {
clazz = "badge-important";
} else if (status === "ERROR") {
clazz = "badge-important";
} else if (status === "TOO_OLD") {
clazz = "badge-important";
} else if (status === "DONE") {
clazz = "badge-success";
}
return '<span class="badge ' + clazz + '">' + i18n(status) + '</span>';
};
})(window.mydmam.notification);

/**
* getAndDisplayTasksJobs
*/
(function(notification, mydmam) {
notification.getAndDisplayTasksJobs = function() {

/**
* displayTaskJob
* Transform Task/Job keys to an informative cartridge
*/
var displayTaskJob = function(dom_element, ajaxdata) {
var key = $(dom_element).text();
if(ajaxdata[key]) {
ajaxdata[key].key = key;
ajaxdata[key].simplekey = mydmam.queue.createSimpleKey(key);
$(dom_element).html(mydmam.queue.createTaskJobTableElement(ajaxdata[key]));
$(dom_element).find(".blocktaskjobdateedit").prepend(notification.displayStatus(ajaxdata[key].status) + ' ');
$(dom_element).find(".taskjobkeyraw").remove();

} else {
$(dom_element).html('<strong>' + i18n("userprofile.notifications.cantfoundtaskjob") + '</strong>');
}
};

var key;
var tasksjobs_keys = [];
var dom_element_list = notification.dom_element_list_for_taskjob_resolve;
for (var pos in dom_element_list) {
key = $(dom_element_list[pos]).text();
if (tasksjobs_keys.indexOf(key) === -1) {
tasksjobs_keys.push(key);
}
}

$.ajax({
url: url_queuegettasksjobs,
type: "POST",
async: true,
data: {
"tasksjobs_keys": tasksjobs_keys
},
error: function(jqXHR, textStatus, errorThrown) {
notification.ajaxError(i18n("userprofile.notifications.errorduringgettasksjobs"), textStatus, errorThrown);
},
success: function(data) {
$(".taskjobsummary").each(function() {
displayTaskJob(this, data);
});
//TODO sort T/J ?
/*
var data = [];
for (var key in rawdata) {
rawdata[key].key = key;
data.push(rawdata[key]);
}
data = data.sort(function(a, b) {
return a.updatedate > b.updatedate ? -1 : 1;
});
* */
}
});
};
})(window.mydmam.notification, window.mydmam);

/**
* postProcessPage
*/
(function(notification) {
notification.postProcessPage = function() {
$(".redrawstatus").each(function() {
$(this).html(notification.displayStatus($(this).data("status")));
});

$(".btnsetreadnotification").each(function() {
$(this).click(notification.setReadNotification);
});
Expand Down
16 changes: 8 additions & 8 deletions public/javascripts/src/mydmam.queue.js
Expand Up @@ -282,9 +282,9 @@
content = content + '<span class="profilecategory">' + current_taskjob.profile_category + '</span> :: ';
content = content + '<strong><span class="taskjobname">' + current_taskjob.name + '</span></strong></div>';

content = content + '<div class="span4">';
content = content + '<div class="span4 blocktaskjobdateedit">';

if (enable_update) {
if (enable_update_queue) {
var display;
if (current_taskjob.status == "PROCESSING" | current_taskjob.status == "PREPARING") {
display = ' style="display:none"';
Expand All @@ -296,19 +296,19 @@
if (current_taskjob.status == "WAITING") {
display = ' style="display:none"';
}
content = content + '<li><a href="#" class="btntskwait" data-emkey="' + key + '"' + display + '>' + i18n('queue.task.setto') + '<strong>' + i18n('WAITING') + '</strong></a></li>';
content = content + '<li><a href="#" class="btntskwait" data-emkey="' + key + '"' + display + '>' + i18n('queue.task.setto') + ' <strong>' + i18n('WAITING') + '</strong></a></li>';
display = "";

if (current_taskjob.status == "POSTPONED") {
display = ' style="display:none"';
}
content = content + '<li><a href="#" class="btntskpostponed" data-emkey="' + key + '"' + display + '>' + i18n('queue.task.setto') + '<strong>' + i18n('POSTPONED') + '</strong></a></li>';
content = content + '<li><a href="#" class="btntskpostponed" data-emkey="' + key + '"' + display + '>' + i18n('queue.task.setto') + ' <strong>' + i18n('POSTPONED') + '</strong></a></li>';
display = "";

if (current_taskjob.status == "CANCELED") {
display = ' style="display:none"';
}
content = content + '<li><a href="#" class="btntskcanceled" data-emkey="' + key + '"' + display + '>' + i18n('queue.task.setto') + '<strong>' + i18n('CANCELED') + '</strong></a></li>';
content = content + '<li><a href="#" class="btntskcanceled" data-emkey="' + key + '"' + display + '>' + i18n('queue.task.setto') + ' <strong>' + i18n('CANCELED') + '</strong></a></li>';
display = "";

if (current_taskjob.priority === 0 || current_taskjob.status == "DONE") {
Expand Down Expand Up @@ -425,7 +425,7 @@
content = content + '<div class="well well-small joblastmessage" style="display:none"></div>';
}

content = content + '<div>Key: <code>' + key + '</code></div>';
content = content + '<div class="taskjobkeyraw">Key: <code>' + key + '</code></div>';
if (current_taskjob.processing_error) {
content = content + '<div style="margin-bottom: 1em;" class="joberror">' + i18n('queue.task.error') + '<br><pre>' + current_taskjob.processing_error + '</pre></div>';
} else {
Expand Down Expand Up @@ -643,7 +643,7 @@
$("#fulltaskjobtable").empty();
$("#fulltaskjobtable").append(content);

if (enable_update) {
if (enable_update_queue) {
for (var pos in selected_taskjoblist) {
queue.addActionsForTaskJobTableElement(selected_taskjoblist[pos].simplekey);
}
Expand Down Expand Up @@ -673,7 +673,7 @@

$("#fulltaskjobtable").prepend(content);

if (enable_update) {
if (enable_update_queue) {
for (var pos in selected_taskjoblist) {
queue.addActionsForTaskJobTableElement(selected_taskjoblist[pos].simplekey);
}
Expand Down

0 comments on commit 83f77f2

Please sign in to comment.