Version 20.33.7: Feb 22, 2021 Code refactoring related to writing a timeline note.

This commit is contained in:
acanas 2021-02-22 13:40:31 +01:00
parent e84b341ebf
commit 36d878fa90
4 changed files with 115 additions and 82 deletions

View File

@ -553,7 +553,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
#define Log_PLATFORM_VERSION "SWAD 20.33.6 (2021-02-22)"
#define Log_PLATFORM_VERSION "SWAD 20.33.7 (2021-02-22)"
#define CSS_FILE "swad20.8.css"
#define JS_FILE "swad20.6.2.js"
/*
@ -601,6 +601,7 @@ TODO: DNI de un estudiante sale err
TODO: BUG: Cuando un tipo de grupo sólo tiene un grupo, inscribirse es voluntario, el estudiante sólo puede pertenecer a un grupo, y se inscribe en él, debería poder desapuntarse. Ahora no puede.
TODO: Salvador Romero Cortés: @acanas opción para editar posts
Version 20.33.7: Feb 22, 2021 Code refactoring related to writing a timeline note. (304923 lines)
Version 20.33.6: Feb 22, 2021 Code refactoring related to writing a timeline note. (304898 lines)
Version 20.33.5: Feb 22, 2021 Code refactoring related to writing a timeline note. (304889 lines)
Version 20.33.4: Feb 22, 2021 Some actions renamed. (304883 lines)

View File

@ -66,18 +66,20 @@ extern struct Globals Gbl;
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static unsigned long TL_Com_GetNumCommentsInNote (long NotCod);
static unsigned TL_Com_WriteHiddenComments (struct TL_Timeline *Timeline,
long NotCod,
char IdComments[Frm_MAX_BYTES_ID + 1],
unsigned NumInitialCommentsToGet);
static void TL_Com_WriteOneCommentInList (struct TL_Timeline *Timeline,
static void TL_Com_WriteOneCommentInList (const struct TL_Timeline *Timeline,
MYSQL_RES *mysql_res);
static void TL_Com_LinkToShowOnlyLatestComments (const char IdComments[Frm_MAX_BYTES_ID + 1]);
static void TL_Com_LinkToShowPreviousComments (const char IdComments[Frm_MAX_BYTES_ID + 1],
unsigned NumInitialComments);
static void TL_Com_PutIconToToggleComments (const char *UniqueId,
const char *Icon,const char *Text);
static void TL_Com_WriteComment (struct TL_Timeline *Timeline,
static void TL_Com_WriteComment (const struct TL_Timeline *Timeline,
struct TL_Com_Comment *Com,
TL_ShowAlone_t ShowCommentAlone); // Comment is shown alone, not in a list
static void TL_Com_WriteAuthorComment (struct UsrData *UsrDat);
@ -173,33 +175,28 @@ void TL_Com_PutHiddenFormToWriteNewComment (const struct TL_Timeline *Timeline,
HTM_DIV_End ();
}
/*****************************************************************************/
/********************* Get number of comments in a note **********************/
/*****************************************************************************/
unsigned long TL_Com_GetNumCommentsInNote (long NotCod)
{
return DB_QueryCOUNT ("can not get number of comments in a note",
"SELECT COUNT(*) FROM tl_pubs"
" WHERE NotCod=%ld AND PubType=%u",
NotCod,(unsigned) TL_Pub_COMMENT_TO_NOTE);
}
/*****************************************************************************/
/*********************** Write comments in a note ****************************/
/*****************************************************************************/
void TL_Com_WriteCommentsInNote (struct TL_Timeline *Timeline,
const struct TL_Not_Note *Not,
unsigned NumComments)
void TL_Com_WriteCommentsInNote (const struct TL_Timeline *Timeline,
const struct TL_Not_Note *Not)
{
MYSQL_RES *mysql_res;
unsigned NumComments;
unsigned NumInitialComments;
unsigned NumFinalCommentsToGet;
unsigned NumFinalCommentsGot;
unsigned NumCom;
char IdComments[Frm_MAX_BYTES_ID + 1];
/***** Get number of comments in note *****/
NumComments = TL_Com_GetNumCommentsInNote (Not->NotCod);
/***** Trivial check: if no comments ==> nothing to do *****/
if (!NumComments)
return;
/***** Compute how many initial comments will be hidden
and how many final comments will be visible *****/
// Never hide only one comment
@ -311,6 +308,18 @@ void TL_Com_WriteCommentsInNote (struct TL_Timeline *Timeline,
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/********************* Get number of comments in a note **********************/
/*****************************************************************************/
static unsigned long TL_Com_GetNumCommentsInNote (long NotCod)
{
return DB_QueryCOUNT ("can not get number of comments in a note",
"SELECT COUNT(*) FROM tl_pubs"
" WHERE NotCod=%ld AND PubType=%u",
NotCod,(unsigned) TL_Pub_COMMENT_TO_NOTE);
}
/*****************************************************************************/
/********************** Write hidden comments via AJAX ***********************/
/*****************************************************************************/
@ -404,7 +413,7 @@ static unsigned TL_Com_WriteHiddenComments (struct TL_Timeline *Timeline,
/************************* Write a comment in list ***************************/
/*****************************************************************************/
static void TL_Com_WriteOneCommentInList (struct TL_Timeline *Timeline,
static void TL_Com_WriteOneCommentInList (const struct TL_Timeline *Timeline,
MYSQL_RES *mysql_res)
{
MYSQL_ROW row;
@ -487,7 +496,7 @@ static void TL_Com_PutIconToToggleComments (const char *UniqueId,
/******************************** Write comment ******************************/
/*****************************************************************************/
static void TL_Com_WriteComment (struct TL_Timeline *Timeline,
static void TL_Com_WriteComment (const struct TL_Timeline *Timeline,
struct TL_Com_Comment *Com,
TL_ShowAlone_t ShowCommentAlone) // Comment is shown alone, not in a list
{

View File

@ -58,11 +58,9 @@ void TL_Com_PutIconCommentDisabled (void);
void TL_Com_PutHiddenFormToWriteNewComment (const struct TL_Timeline *Timeline,
long NotCod,
const char IdNewComment[Frm_MAX_BYTES_ID + 1]);
unsigned long TL_Com_GetNumCommentsInNote (long NotCod);
void TL_Com_WriteCommentsInNote (struct TL_Timeline *Timeline,
const struct TL_Not_Note *Not,
unsigned NumComments);
void TL_Com_WriteCommentsInNote (const struct TL_Timeline *Timeline,
const struct TL_Not_Note *Not);
void TL_Com_ShowHiddenCommentsUsr (void);
void TL_Com_ShowHiddenCommentsGbl (void);

View File

@ -83,6 +83,13 @@ static void TL_Not_WriteLocationInHierarchy (const struct TL_Not_Note *Not,
static void TL_Not_PutFormGoToAction (const struct TL_Not_Note *Not,
const struct For_Forums *Forums);
static void TL_Not_WriteFootAndComments (const struct TL_Timeline *Timeline,
const struct TL_Not_Note *Not,
long AuthorUsrCod);
static void TL_Not_WriteFoot (const struct TL_Timeline *Timeline,
const struct TL_Not_Note *Not,
long AuthorUsrCod);
static void TL_Not_PutFormToRemoveNote (const struct TL_Timeline *Timeline,
long NotCod);
@ -196,12 +203,7 @@ void TL_Not_WriteNote (struct TL_Timeline *Timeline,
TL_ShowAlone_t ShowNoteAlone) // Note is shown alone, not in a list
{
struct UsrData AuthorDat;
bool IAmTheAuthor;
unsigned NumComments;
char IdNewComment[Frm_MAX_BYTES_ID + 1];
static unsigned NumDiv = 0; // Used to create unique div id for fav and shared
NumDiv++;
/***** Begin box ****/
if (ShowNoteAlone == TL_SHOW_ALONE)
@ -237,7 +239,6 @@ void TL_Not_WriteNote (struct TL_Timeline *Timeline,
/***** Get author data *****/
AuthorDat.UsrCod = Not->UsrCod;
Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&AuthorDat,Usr_DONT_GET_PREFS);
IAmTheAuthor = Usr_ItsMe (AuthorDat.UsrCod);
/***** Left: write author's photo *****/
TL_Not_ShowAuthorPhoto (&AuthorDat);
@ -265,9 +266,6 @@ void TL_Not_WriteNote (struct TL_Timeline *Timeline,
/* Create unique id for new comment */
Frm_SetUniqueId (IdNewComment);
/* Get number of comments in this note */
NumComments = TL_Com_GetNumCommentsInNote (Not->NotCod);
/* Put icon to add a comment */
HTM_DIV_Begin ("class=\"TL_BOTTOM_LEFT\"");
if (Not->Unavailable) // Unavailable notes can not be commented
@ -276,39 +274,8 @@ void TL_Not_WriteNote (struct TL_Timeline *Timeline,
TL_Com_PutIconToToggleComment (IdNewComment);
HTM_DIV_End ();
/* Start container for buttons and comments */
HTM_DIV_Begin ("class=\"TL_BOTTOM_RIGHT TL_RIGHT_WIDTH\"");
/* Start foot container */
HTM_DIV_Begin ("class=\"TL_FOOT TL_RIGHT_WIDTH\"");
/* Foot column 1: Fav zone */
HTM_DIV_Begin ("id=\"fav_not_%s_%u\" class=\"TL_FAV_NOT TL_FAV_NOT_WIDTH\"",
Gbl.UniqueNameEncrypted,NumDiv);
TL_Fav_PutFormToFavUnfNote (Not,TL_Usr_SHOW_FEW_USRS);
HTM_DIV_End ();
/* Foot column 2: Share zone */
HTM_DIV_Begin ("id=\"sha_not_%s_%u\" class=\"TL_SHA_NOT TL_SHA_NOT_WIDTH\"",
Gbl.UniqueNameEncrypted,NumDiv);
TL_Sha_PutFormToShaUnsNote (Not,TL_Usr_SHOW_FEW_USRS);
HTM_DIV_End ();
/* Foot column 3: Icon to remove this note */
HTM_DIV_Begin ("class=\"TL_REM\"");
if (IAmTheAuthor)
TL_Not_PutFormToRemoveNote (Timeline,Not->NotCod);
HTM_DIV_End ();
/* End foot container */
HTM_DIV_End ();
/* Comments */
if (NumComments)
TL_Com_WriteCommentsInNote (Timeline,Not,NumComments);
/* End container for buttons and comments */
HTM_DIV_End ();
/* Write foot and comments */
TL_Not_WriteFootAndComments (Timeline,Not,AuthorDat.UsrCod);
/* Put hidden form to write a new comment */
TL_Com_PutHiddenFormToWriteNewComment (Timeline,Not->NotCod,IdNewComment);
@ -754,6 +721,80 @@ void TL_Not_GetNoteSummary (const struct TL_Not_Note *Not,
}
}
/*****************************************************************************/
/******************** Write foot and comments of a note **********************/
/*****************************************************************************/
static void TL_Not_WriteFootAndComments (const struct TL_Timeline *Timeline,
const struct TL_Not_Note *Not,
long AuthorUsrCod)
{
/***** Begin container for foot and comments *****/
HTM_DIV_Begin ("class=\"TL_BOTTOM_RIGHT TL_RIGHT_WIDTH\"");
/***** Write foot of a note *****/
TL_Not_WriteFoot (Timeline,Not,AuthorUsrCod);
/***** Comments *****/
TL_Com_WriteCommentsInNote (Timeline,Not);
/***** End container for buttons and comments *****/
HTM_DIV_End ();
}
/*****************************************************************************/
/*************************** Write foot of a note ****************************/
/*****************************************************************************/
static void TL_Not_WriteFoot (const struct TL_Timeline *Timeline,
const struct TL_Not_Note *Not,
long AuthorUsrCod)
{
static unsigned NumDiv = 0; // Used to create unique div id for fav and shared
NumDiv++;
/***** Begin foot container *****/
HTM_DIV_Begin ("class=\"TL_FOOT TL_RIGHT_WIDTH\"");
/***** Foot column 1: Fav zone *****/
HTM_DIV_Begin ("id=\"fav_not_%s_%u\" class=\"TL_FAV_NOT TL_FAV_NOT_WIDTH\"",
Gbl.UniqueNameEncrypted,NumDiv);
TL_Fav_PutFormToFavUnfNote (Not,TL_Usr_SHOW_FEW_USRS);
HTM_DIV_End ();
/***** Foot column 2: Share zone *****/
HTM_DIV_Begin ("id=\"sha_not_%s_%u\" class=\"TL_SHA_NOT TL_SHA_NOT_WIDTH\"",
Gbl.UniqueNameEncrypted,NumDiv);
TL_Sha_PutFormToShaUnsNote (Not,TL_Usr_SHOW_FEW_USRS);
HTM_DIV_End ();
/***** Foot column 3: Icon to remove this note *****/
HTM_DIV_Begin ("class=\"TL_REM\"");
if (Usr_ItsMe (AuthorUsrCod)) // I am the author
TL_Not_PutFormToRemoveNote (Timeline,Not->NotCod);
HTM_DIV_End ();
/***** End foot container *****/
HTM_DIV_End ();
}
/*****************************************************************************/
/**************************** Form to remove note ****************************/
/*****************************************************************************/
static void TL_Not_PutFormToRemoveNote (const struct TL_Timeline *Timeline,
long NotCod)
{
extern const char *Txt_Remove;
/***** Form to remove publication *****/
TL_Frm_FormStart (Timeline,TL_Frm_REQ_REM_NOTE);
TL_Not_PutHiddenParamNotCod (NotCod);
Ico_PutIconLink ("trash.svg",Txt_Remove);
Frm_EndForm ();
}
/*****************************************************************************/
/***************** Store and publish a note into database ********************/
/*****************************************************************************/
@ -952,22 +993,6 @@ void TL_Not_MarkNotesChildrenOfFolderAsUnavailable (const char *Path)
}
}
/*****************************************************************************/
/************************ Form to remove publication *************************/
/*****************************************************************************/
static void TL_Not_PutFormToRemoveNote (const struct TL_Timeline *Timeline,
long NotCod)
{
extern const char *Txt_Remove;
/***** Form to remove publication *****/
TL_Frm_FormStart (Timeline,TL_Frm_REQ_REM_NOTE);
TL_Not_PutHiddenParamNotCod (NotCod);
Ico_PutIconLink ("trash.svg",Txt_Remove);
Frm_EndForm ();
}
/*****************************************************************************/
/****************** Put parameter with the code of a note ********************/
/*****************************************************************************/