From a858f03eb5c3f4b3d8ddd5bf94d8eec4bcb45453 Mon Sep 17 00:00:00 2001 From: acanas Date: Fri, 29 Sep 2023 14:42:04 +0200 Subject: [PATCH] Version 23.19.1: Sep 29, 2023 Code refactoring in file browser. --- swad_assignment.c | 29 +++++++++++++++++++++++++++++ swad_assignment.h | 1 + swad_browser.c | 23 ++--------------------- swad_changelog.h | 3 ++- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/swad_assignment.c b/swad_assignment.c index 99f2c0cf..6f661fbf 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -1699,6 +1699,35 @@ bool Asg_CheckIfICanCreateIntoAssigment (const struct Asg_Assignment *Asg) } } +/*****************************************************************************/ +/*************************** Set assignment folder ***************************/ +/*****************************************************************************/ + +void Asg_SetFolder (struct Asg_Assignment *Asg,unsigned Level) + { + const char *Ptr; + unsigned i; + + if (Level == 1) + // We are in this case: assignments/assignment-folder + Str_Copy (Asg->Folder,Gbl.FileBrowser.FilFolLnk.Name, + sizeof (Asg->Folder) - 1); + else + { + // We are in this case: assignments/assignment-folder/rest-of-path + for (Ptr = Gbl.FileBrowser.FilFolLnk.Path; + *Ptr && *Ptr != '/'; + Ptr++); // Go to first '/' + if (*Ptr == '/') + Ptr++; // Skip '/' + for (i = 0; + i < Brw_MAX_BYTES_FOLDER && *Ptr && *Ptr != '/'; + i++, Ptr++) + Asg->Folder[i] = *Ptr; // Copy assignment folder + Asg->Folder[i] = '\0'; + } + } + /*****************************************************************************/ /************************ Get number of assignments **************************/ /*****************************************************************************/ diff --git a/swad_assignment.h b/swad_assignment.h index 4ebe6713..585dd1e3 100644 --- a/swad_assignment.h +++ b/swad_assignment.h @@ -107,6 +107,7 @@ void Asg_RemoveCrsAssignments (long CrsCod); void Asg_WriteDatesAssignment (const struct Asg_Assignment *Asg); bool Asg_CheckIfICanCreateIntoAssigment (const struct Asg_Assignment *Asg); +void Asg_SetFolder (struct Asg_Assignment *Asg,unsigned Level); unsigned Asg_GetNumAssignments (Hie_Level_t Level,unsigned *NumNotif); diff --git a/swad_browser.c b/swad_browser.c index ea1882bf..8c57220b 100644 --- a/swad_browser.c +++ b/swad_browser.c @@ -2166,7 +2166,6 @@ void Brw_PutParsFileBrowser (const char *PathInTree,const char *FilFolLnkName, static void Brw_GetParsPathInTreeAndFileName (void) { const char *Ptr; - unsigned i; Brw_FileType_t FileType; char FileNameToShow[NAME_MAX + 1]; @@ -2218,24 +2217,7 @@ static void Brw_GetParsPathInTreeAndFileName (void) /***** Get data of assignment *****/ if (Gbl.FileBrowser.Level && Brw_TypeIsAdmAsg[Gbl.FileBrowser.Type]) { - if (Gbl.FileBrowser.Level == 1) - // We are in this case: assignments/assignment-folder - Str_Copy (Gbl.FileBrowser.Asg.Folder,Gbl.FileBrowser.FilFolLnk.Name, - sizeof (Gbl.FileBrowser.Asg.Folder) - 1); - else - { - // We are in this case: assignments/assignment-folder/rest-of-path - for (Ptr = Gbl.FileBrowser.FilFolLnk.Path; - *Ptr && *Ptr != '/'; - Ptr++); // Go to first '/' - if (*Ptr == '/') - Ptr++; // Skip '/' - for (i = 0; - i < Brw_MAX_BYTES_FOLDER && *Ptr && *Ptr != '/'; - i++, Ptr++) - Gbl.FileBrowser.Asg.Folder[i] = *Ptr; // Copy assignment folder - Gbl.FileBrowser.Asg.Folder[i] = '\0'; - } + Asg_SetFolder (&Gbl.FileBrowser.Asg,Gbl.FileBrowser.Level); Asg_GetAssignmentDataByFolder (&Gbl.FileBrowser.Asg); } } @@ -4076,8 +4058,7 @@ static bool Brw_WriteRowFileBrowser (unsigned Level,const char *RowId, { if (Level == 1) // Main folder of the assignment { - Str_Copy (Gbl.FileBrowser.Asg.Folder,Gbl.FileBrowser.FilFolLnk.Name, - sizeof (Gbl.FileBrowser.Asg.Folder) - 1); + Asg_SetFolder (&Gbl.FileBrowser.Asg,Level); Asg_GetAssignmentDataByFolder (&Gbl.FileBrowser.Asg); // The data of this assignment remains in Gbl.FileBrowser.Asg // for all subsequent rows with Level > 1 (files or folders inside this folder), diff --git a/swad_changelog.h b/swad_changelog.h index 6e8c05f8..461a4085 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -632,10 +632,11 @@ TODO: Francisco Javier Fern Me sale este error, no sé si por no recordar yo la sintaxis apropiada para mandar a varios destinatarios. ¿No era así? "can npt create received message (duplicated entry '243218-2160773' for key 'UsrCod_MsgCod') */ -#define Log_PLATFORM_VERSION "SWAD 23.19 (2023-09-29)" +#define Log_PLATFORM_VERSION "SWAD 23.19.1 (2023-09-29)" #define CSS_FILE "swad23.16.1.css" #define JS_FILE "swad22.49.js" /* + Version 23.19.1: Sep 29, 2023 Code refactoring in file browser. (336609 lines) Version 23.19: Sep 29, 2023 Code refactoring in file browser. (336600 lines) Version 23.18: Sep 29, 2023 Code refactoring in file browser. (336670 lines) Version 23.17.5: Sep 28, 2023 Code refactoring in scopes. (336638 lines)