Verified Commit b5349171 authored by David Beniamine's avatar David Beniamine
Browse files

Merge branch '471-ameliorer-le-title-sur-les-etoiles-de-ld' of...

Merge branch '471-ameliorer-le-title-sur-les-etoiles-de-ld' of gricad-gitlab.univ-grenoble-alpes.fr:labnbook/labnbook
parents 5af51e97 16402c46
......@@ -46,5 +46,4 @@ storage/cache/
tests/_output
patch
.env.dev
.idea/
......@@ -463,7 +463,8 @@ class ReportController extends Controller
abort_if($user->cannot($perm, $report), Helper::pullPolicyErrorCode(), Helper::pullPolicyErrorMessage());
$edited_ld = (int) $request->input('edited_ld');
$message = (int)$request->input('message');
return response($report->synchronize($user, $scope, $edited_ld, $message));
return response($report->synchronize($user, $scope, $edited_ld, $message))->header('Content-Type', 'application/xml');
}
/**
......
......@@ -78,6 +78,13 @@ class Report extends Model
const UPDATED_AT = 'update_time';
const DELETED_AT = 'delete_time';
/**
* Constants used in synchronzize
*/
const STATUS_FREE = "free_ld";
const STATUS_LOCKED = "locked_ld";
const STATUS_MODIFIED = "modified_ld";
public $timestamps = false;
public $fillable = ['id_mission', 'team_name', 'status', 'start_datetime',
......@@ -746,33 +753,35 @@ ORDER BY labdoc.id_report_part, labdoc.position"
$id_ld = $ld->id_labdoc;
$id_rp = $ld->id_report_part;
if ($ld->deleted == 1) { // le labdoc doit être supprimé
if ($ld->deleted == 1) { // Labdoc must be deleted
$XML_doc->addXMLLD("deleted", null, $id_ld, $id_rp);
} else {
// suppression du lock si le LD n'a pas été correctement fermé par le précédent utilisateur
// Delete lock if LD was not correctly closed by previous user
$modify_ld = $ld->unsetObsoleteLock($user->id_user);
// Cas d'une modification de LD => envoi de la ref du LD, du nom et du contenu
// Modified LD => send LD ref, name and content
if ($ld->modified == 1 || $modify_ld) {
$XML_doc->addXMLModifiedLD($id_ld, $id_rp, htmlspecialchars($ld->name), $ld->labdoc_data);
$ld->updateStatus(['modified'=>0], $user->id_user);
}
// Cas d'un déplacement de LD => envoi de la ref du LD ET de sa position dans la RP
// Moved LD => send LD ref, name and content and position in RP
if ($ld->moved == 1) {
$XML_doc->addXMLLD("moved", $ld->position, $id_ld, $id_rp);
}
// Gestion du statut draft modifié => il faut renvoyer le statut
// Draft status management => resent status
if ($ld->drafted == 1) {
$XML_doc->addXMLLD("drafted", $ld->draft, $id_ld, $id_rp);
$ld->updateStatus(['drafted'=>0], $user->id_user);
}
// Statut du LD => envoi de la ref du LD et du statut : free / new / locked (name of the locker)
// LD status => send LD ref, status (free_ld / modified_ld / locked_ld) + editor ( modified / locked ) + last_edition (modified)
if ($ld->locked !== null && $ld->last_editor != $user->id_user) {
$XML_doc->addXMLLD("ld_list", htmlspecialchars($ld->user_last_editor->first_name . ' ' . $ld->user_last_editor->user_name), $id_ld, $id_rp);
$lastEditorFullName= htmlspecialchars($ld->user_last_editor->first_name . ' ' . $ld->user_last_editor->user_name);
$XML_doc->addXMLInfoStatusLD($id_ld, $id_rp, Report::STATUS_LOCKED, $lastEditorFullName);
} elseif ($ld->mod_icon == 1) {
$XML_doc->addXMLLD("ld_list", "modified_ld", $id_ld, $id_rp);
$lastEditorFullName = htmlspecialchars($ld->user_last_editor->first_name . ' ' . $ld->user_last_editor->user_name);
$XML_doc->addXMLInfoStatusLD($id_ld, $id_rp, Report::STATUS_MODIFIED, $lastEditorFullName, $ld->last_edition);
} else {
$XML_doc->addXMLLD("ld_list", "free_ld", $id_ld, $id_rp);
$XML_doc->addXMLInfoStatusLD( $id_ld, $id_rp, Report::STATUS_FREE);
}
}
}
......
......@@ -8,7 +8,7 @@ class XmlDoc
{
/** @var $domDoc DomDocument */
private $domDoc;
public function __construct() {
$this->domDoc = new DomDocument();
}
......@@ -34,6 +34,42 @@ class XmlDoc
$xml_parent->appendChild($xml_ld);
}
/**
* @param int $id_ld
* @param int $id_rp
* @param string $status
* @param string $lastEditorFullName
* @param string $last_edition
* Add information in XML ld_list for Report synchronize method
*/
public function addXMLInfoStatusLD($id_ld, $id_rp, $status, $lastEditorFullName="", $last_edition=""){
$xml_ld = $this->domDoc->createElement("ld");
$xml_ld->setAttribute("id_ld", $id_ld);
$xml_ld->setAttribute("id_rp", $id_rp);
$xml_status = $this->domDoc->createElement("status");
$xml_status_content = $this->domDoc->createTextNode($status);
$xml_status->appendChild($xml_status_content);
$xml_ld->appendChild($xml_status);
if($status===Report::STATUS_LOCKED || $status===Report::STATUS_MODIFIED){
$xml_editor = $this->domDoc->createElement("editor");
$xml_editor_content = $this->domDoc->createTextNode($lastEditorFullName);
$xml_editor->appendChild($xml_editor_content);
$xml_ld->appendChild($xml_editor);
if($status===Report::STATUS_MODIFIED){
$xml_last_edition = $this->domDoc->createElement("last_edition");
$xml_last_edition_content = $this->domDoc->createTextNode(date('d/m/y - H:i:s',$last_edition));
$xml_last_edition->appendChild($xml_last_edition_content);
$xml_ld->appendChild($xml_last_edition);
}
}
$xml_parent = $this->domDoc->getElementsByTagName("ld_list");
$xml_parent->item(0)->appendChild($xml_ld);
}
/**
* @param int $id_ld
* @param int $id_rp
......@@ -55,7 +91,7 @@ class XmlDoc
$xml_content_content = $this->domDoc->createTextNode($content);
$xml_content->appendChild($xml_content_content);
$xml_ld->appendChild($xml_content);
$xml_parent = $this->domDoc->getElementsByTagName("modified");
$xml_parent->item(0)->appendChild($xml_ld);
}
......@@ -112,5 +148,4 @@ class XmlDoc
public function createElement($name, $value) {
return $this->domDoc->createElement($name, $value);
}
}
......@@ -122,7 +122,7 @@ function synchronize(id_report) { // cette fonction est lancée toutes les $cfg[
}
});
// MODIFIED LD -> refresh the header and the content
// MODIFIED LD -> refresh the content
$(data).find('modified ld').each(function () {
var id_ld = $(this).attr('id_ld');
var id_rp = $(this).attr('id_rp');
......@@ -192,11 +192,13 @@ function synchronize(id_report) { // cette fonction est lancée toutes les $cfg[
}
// LD STATUS CHECK -> free / new / locked = name of the locker
// This part is used to update header icon on labdoc ( none / locked / modified )
$(data).find('ld_list ld').each(function () {
var id_ld = $(this).attr('id_ld');
var response = $(this).text();
var status = $(this).find('status').text();
var header = $("#ld_name_actions_"+id_ld);
if (response == "free_ld") {
if (status == "free_ld") {
if (header.hasClass('ld_new') || header.hasClass('ld_locked')) {
// console.log("setfree", id_ld);
header.removeClass('ld_new').removeClass('ld_locked');
......@@ -204,22 +206,27 @@ function synchronize(id_report) { // cette fonction est lancée toutes les $cfg[
header.find(".modified_ld").hide();
header.find(".lb_ld_menu_btn").show();
}
} else if (response == "modified_ld") {
} else if (status == "modified_ld") {
if (!(header.hasClass('ld_new'))) {
// console.log("modified ld", id_ld);
header.addClass('ld_new').removeClass('ld_locked');
header.find(".locked_ld").hide();
header.find(".modified_ld").show();
var editor = $(this).find("editor").text();
var last_edition = $(this).find("last_edition").text();
var new_title = __("Dernière modification faite par : {{editor}} le ", {editor: editor}) + last_edition + __("- cliquez pour éteindre.");
header.find(".modified_ld").attr('title', new_title);
header.find(".lb_ld_menu_btn").show();
}
} else if (!(header.hasClass('ld_locked'))) {
} else if (status == "locked_ld") {
// console.log("lock ld", id_ld);
header.removeClass('ld_new').addClass('ld_locked');
header.find(".locked_ld").show();
header.find(".locked_ld").attr('title', "Labdoc en cours de modification par "+response);
var new_title = __("Labdoc en cours de modification par: {{editor}}", { editor : $(this).find('editor').text()});
header.find(".locked_ld").attr('title', new_title);
header.find(".modified_ld").hide();
header.find(".lb_ld_menu_btn").hide();
}
}
});
// DRAFTED LD -> change the "drafts" elements
......
......@@ -32,13 +32,16 @@
} else {
echo ' display:none"></i>';
}
echo '<i class="fa fa-star modified_ld" title="'.__('Le LabDoc a été modifié par un étudiant de l\'équipe - cliquez pour éteindre').'" style="color:#ffbd00; ';
if (!$ldv->getLdStatus()->mod_icon || $ld_locked || $ldv->edition) {
echo ' display:none"';
} else {
echo '"';
if ($ldv->ld->user_last_editor) {
echo '<i class="fa fa-star modified_ld" title="'. __("Dernière modification faite par :editorFirstName le :dateEdition - cliquez pour éteindre", ["editorFirstName" => htmlspecialchars($ldv->ld->user_last_editor->first_name . ' ' . $ldv->ld->user_last_editor->user_name), "dateEdition" => htmlspecialchars(date('d/m/y - H:i:s', $ldv->ld->last_edition))]) .'" style="color:#ffbd00; ';
if (!$ldv->getLdStatus()->mod_icon || $ld_locked || $ldv->edition) {
echo ' display:none"';
} else {
echo '"';
}
echo '></i></td>';
}
echo '></i></td>';
}
// Button for showing / hiding the LD
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment