Version 20.35.1: Feb 23, 2021 Code refactoring in timeline related to sharing and faving.

This commit is contained in:
acanas 2021-02-23 11:05:18 +01:00
parent 86775586fe
commit 48f41a9357
5 changed files with 83 additions and 74 deletions

View File

@ -553,7 +553,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD: En OpenSWAD:
ps2pdf source.ps destination.pdf ps2pdf source.ps destination.pdf
*/ */
#define Log_PLATFORM_VERSION "SWAD 20.34.1 (2021-02-23)" #define Log_PLATFORM_VERSION "SWAD 20.35.1 (2021-02-23)"
#define CSS_FILE "swad20.33.9.css" #define CSS_FILE "swad20.33.9.css"
#define JS_FILE "swad20.6.2.js" #define JS_FILE "swad20.6.2.js"
/* /*
@ -601,6 +601,8 @@ 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: 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 TODO: Salvador Romero Cortés: @acanas opción para editar posts
Version 20.35.1: Feb 23, 2021 Code refactoring in timeline related to sharing and faving. (305021 lines)
Version 20.35: Feb 23, 2021 Code refactoring in timeline related to sharing and faving. (304986 lines)
Version 20.34.1: Feb 23, 2021 Code refactoring in timeline related to sharing and faving. (305009 lines) Version 20.34.1: Feb 23, 2021 Code refactoring in timeline related to sharing and faving. (305009 lines)
Version 20.34: Feb 23, 2021 Code refactoring in timeline related to sharing and faving. (305011 lines) Version 20.34: Feb 23, 2021 Code refactoring in timeline related to sharing and faving. (305011 lines)
Version 20.33.11: Feb 23, 2021 Code refactoring in timeline. (305001 lines) Version 20.33.11: Feb 23, 2021 Code refactoring in timeline. (305001 lines)

View File

@ -410,28 +410,28 @@ static void TL_Fav_PutFormToFavUnfNote (long NotCod)
{ {
extern const char *Txt_TIMELINE_Favourite; extern const char *Txt_TIMELINE_Favourite;
extern const char *Txt_TIMELINE_Mark_as_favourite; extern const char *Txt_TIMELINE_Mark_as_favourite;
bool FavUnf; struct TL_Form Form[2] =
static TL_Frm_Action_t Action[2] =
{ {
TL_Frm_FAV_NOTE, // Not faved ==> fav [false] = // I have not faved ==> fav
TL_Frm_UNF_NOTE, // Faved ==> unfav {
.Action = TL_Frm_FAV_NOTE,
.ParamFormat = "NotCod=%ld",
.ParamCod = NotCod,
.Icon = TL_Fav_ICON_FAV,
.Title = Txt_TIMELINE_Mark_as_favourite,
},
[true] = // I have faved ==> unfav
{
.Action = TL_Frm_UNF_NOTE,
.ParamFormat = "NotCod=%ld",
.ParamCod = NotCod,
.Icon = TL_Fav_ICON_FAVED,
.Title = Txt_TIMELINE_Favourite,
},
}; };
static const char *Icon[2] =
{
TL_Fav_ICON_FAV, // Not faved ==> put icon to fav
TL_Fav_ICON_FAVED, // Faved ==> put icon to unfav
};
const char *Title[2] =
{
Txt_TIMELINE_Mark_as_favourite, // Not faved ==> put text to fav
Txt_TIMELINE_Favourite, // Faved ==> put text to unfav
};
/***** Select whether fav/unfav *****/
FavUnf = TL_Fav_CheckIfNoteIsFavedByUsr (NotCod,Gbl.Usrs.Me.UsrDat.UsrCod); // I have favourited this note
/***** Form and icon to fav/unfav note *****/ /***** Form and icon to fav/unfav note *****/
TL_Frm_FormFavSha (Action[FavUnf],"NotCod=%ld",NotCod,Icon[FavUnf],Title[FavUnf]); TL_Frm_FormFavSha (&Form[TL_Fav_CheckIfNoteIsFavedByUsr (NotCod,Gbl.Usrs.Me.UsrDat.UsrCod)]);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -442,28 +442,28 @@ static void TL_Fav_PutFormToFavUnfComm (long PubCod)
{ {
extern const char *Txt_TIMELINE_Favourite; extern const char *Txt_TIMELINE_Favourite;
extern const char *Txt_TIMELINE_Mark_as_favourite; extern const char *Txt_TIMELINE_Mark_as_favourite;
bool FavUnf; struct TL_Form Form[2] =
static TL_Frm_Action_t Action[2] =
{ {
TL_Frm_FAV_COMM, // Not faved ==> fav [false] = // I have not faved ==> fav
TL_Frm_UNF_COMM, // Faved ==> unfav {
.Action = TL_Frm_FAV_COMM,
.ParamFormat = "PubCod=%ld",
.ParamCod = PubCod,
.Icon = TL_Fav_ICON_FAV,
.Title = Txt_TIMELINE_Mark_as_favourite,
},
[true] = // I have faved ==> unfav
{
.Action = TL_Frm_UNF_COMM,
.ParamFormat = "PubCod=%ld",
.ParamCod = PubCod,
.Icon = TL_Fav_ICON_FAVED,
.Title = Txt_TIMELINE_Favourite,
},
}; };
static const char *Icon[2] =
{
TL_Fav_ICON_FAV, // Not faved ==> put icon to fav
TL_Fav_ICON_FAVED, // Faved ==> put icon to unfav
};
const char *Title[2] =
{
Txt_TIMELINE_Mark_as_favourite, // Not faved ==> put text to fav
Txt_TIMELINE_Favourite, // Faved ==> put text to unfav
};
/***** Select whether fav/unfav *****/
FavUnf = TL_Fav_CheckIfNoteIsFavedByUsr (PubCod,Gbl.Usrs.Me.UsrDat.UsrCod); // I have favourited this comment
/***** Form and icon to fav/unfav *****/ /***** Form and icon to fav/unfav *****/
TL_Frm_FormFavSha (Action[FavUnf],"PubCod=%ld",PubCod,Icon[FavUnf],Title[FavUnf]); TL_Frm_FormFavSha (&Form[TL_Fav_CheckIfNoteIsFavedByUsr (PubCod,Gbl.Usrs.Me.UsrDat.UsrCod)]);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -128,15 +128,23 @@ void TL_Frm_PutFormToSeeAllFaversSharers (TL_Frm_Action_t Action,
TL_Usr_HowManyUsrs_t HowManyUsrs) TL_Usr_HowManyUsrs_t HowManyUsrs)
{ {
extern const char *Txt_View_all_USERS; extern const char *Txt_View_all_USERS;
struct TL_Form Form =
{
.Action = Action,
.ParamFormat = ParamFormat,
.ParamCod = ParamCod,
.Icon = TL_Frm_ICON_ELLIPSIS,
.Title = Txt_View_all_USERS,
};
switch (HowManyUsrs) switch (HowManyUsrs)
{ {
case TL_Usr_SHOW_FEW_USRS: case TL_Usr_SHOW_FEW_USRS:
/***** Form and icon to mark note as favourite *****/ /***** Form and icon to view all users *****/
TL_Frm_FormFavSha (Action,ParamFormat,ParamCod, TL_Frm_FormFavSha (&Form);
TL_Frm_ICON_ELLIPSIS,Txt_View_all_USERS);
break; break;
case TL_Usr_SHOW_ALL_USRS: case TL_Usr_SHOW_ALL_USRS:
/***** Disabled icon *****/
Ico_PutIconOff (TL_Frm_ICON_ELLIPSIS,Txt_View_all_USERS); Ico_PutIconOff (TL_Frm_ICON_ELLIPSIS,Txt_View_all_USERS);
break; break;
} }
@ -146,15 +154,13 @@ void TL_Frm_PutFormToSeeAllFaversSharers (TL_Frm_Action_t Action,
/******* Form to fav/unfav or share/unshare in global or user timeline *******/ /******* Form to fav/unfav or share/unshare in global or user timeline *******/
/*****************************************************************************/ /*****************************************************************************/
void TL_Frm_FormFavSha (TL_Frm_Action_t Action, void TL_Frm_FormFavSha (const struct TL_Form *Form)
const char *ParamFormat,long ParamCod,
const char *Icon,const char *Title)
{ {
char *OnSubmit; char *OnSubmit;
char ParamStr[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; char ParamStr[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
/***** Create parameter string *****/ /***** Create parameter string *****/
sprintf (ParamStr,ParamFormat,ParamCod); sprintf (ParamStr,Form->ParamFormat,Form->ParamCod);
/* /*
+---------------------------------------------------------------------------+ +---------------------------------------------------------------------------+
@ -178,7 +184,7 @@ void TL_Frm_FormFavSha (TL_Frm_Action_t Action,
if (asprintf (&OnSubmit,"updateDivFaversSharers(this," if (asprintf (&OnSubmit,"updateDivFaversSharers(this,"
"'act=%ld&ses=%s&%s&OtherUsrCod=%s');" "'act=%ld&ses=%s&%s&OtherUsrCod=%s');"
" return false;", // return false is necessary to not submit form " return false;", // return false is necessary to not submit form
Act_GetActCod (TL_Frm_ActionUsr[Action]), Act_GetActCod (TL_Frm_ActionUsr[Form->Action]),
Gbl.Session.Id, Gbl.Session.Id,
ParamStr, ParamStr,
Gbl.Usrs.Other.UsrDat.EnUsrCod) < 0) Gbl.Usrs.Other.UsrDat.EnUsrCod) < 0)
@ -190,13 +196,13 @@ void TL_Frm_FormFavSha (TL_Frm_Action_t Action,
if (asprintf (&OnSubmit,"updateDivFaversSharers(this," if (asprintf (&OnSubmit,"updateDivFaversSharers(this,"
"'act=%ld&ses=%s&%s');" "'act=%ld&ses=%s&%s');"
" return false;", // return false is necessary to not submit form " return false;", // return false is necessary to not submit form
Act_GetActCod (TL_Frm_ActionGbl[Action]), Act_GetActCod (TL_Frm_ActionGbl[Form->Action]),
Gbl.Session.Id, Gbl.Session.Id,
ParamStr) < 0) ParamStr) < 0)
Lay_NotEnoughMemoryExit (); Lay_NotEnoughMemoryExit ();
Frm_StartFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit); Frm_StartFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit);
} }
Ico_PutIconLink (Icon,Title); Ico_PutIconLink (Form->Icon,Form->Title);
Frm_EndForm (); Frm_EndForm ();
/* Free allocated memory */ /* Free allocated memory */

View File

@ -27,12 +27,6 @@
/********************************** Headers **********************************/ /********************************** Headers **********************************/
/*****************************************************************************/ /*****************************************************************************/
// #include "swad_form.h"
// #include "swad_media.h"
// #include "swad_notification.h"
// #include "swad_user.h"
// #include "swad_timeline_user.h"
/*****************************************************************************/ /*****************************************************************************/
/****************************** Public constants *****************************/ /****************************** Public constants *****************************/
/*****************************************************************************/ /*****************************************************************************/
@ -70,6 +64,15 @@ typedef enum
TL_Frm_SHO_HID_COMM, // Show / hide comments TL_Frm_SHO_HID_COMM, // Show / hide comments
} TL_Frm_Action_t; } TL_Frm_Action_t;
struct TL_Form
{
TL_Frm_Action_t Action;
const char *ParamFormat;
long ParamCod;
const char *Icon;
const char *Title;
};
/*****************************************************************************/ /*****************************************************************************/
/****************************** Public prototypes ****************************/ /****************************** Public prototypes ****************************/
/*****************************************************************************/ /*****************************************************************************/
@ -79,9 +82,7 @@ void TL_Frm_FormStart (const struct TL_Timeline *Timeline,TL_Frm_Action_t Action
void TL_Frm_PutFormToSeeAllFaversSharers (TL_Frm_Action_t Action, void TL_Frm_PutFormToSeeAllFaversSharers (TL_Frm_Action_t Action,
const char *ParamFormat,long ParamCod, const char *ParamFormat,long ParamCod,
TL_Usr_HowManyUsrs_t HowManyUsrs); TL_Usr_HowManyUsrs_t HowManyUsrs);
void TL_Frm_FormFavSha (TL_Frm_Action_t Action, void TL_Frm_FormFavSha (const struct TL_Form *Form);
const char *ParamFormat,long ParamCod,
const char *Icon,const char *Title);
void TL_Frm_FormToShowHiddenComments (long NotCod, void TL_Frm_FormToShowHiddenComments (long NotCod,
char IdComments[Frm_MAX_BYTES_ID + 1], char IdComments[Frm_MAX_BYTES_ID + 1],

View File

@ -254,28 +254,28 @@ static void TL_Sha_PutFormToShaUnsNote (long NotCod)
{ {
extern const char *Txt_TIMELINE_Shared; extern const char *Txt_TIMELINE_Shared;
extern const char *Txt_TIMELINE_Share; extern const char *Txt_TIMELINE_Share;
bool ShaUns; struct TL_Form Form[2] =
static TL_Frm_Action_t Action[2] =
{ {
TL_Frm_SHA_NOTE, // Not shared ==> share [false] = // I have not shared ==> share
TL_Frm_UNS_NOTE, // Shared ==> unshare {
.Action = TL_Frm_SHA_NOTE,
.ParamFormat = "NotCod=%ld",
.ParamCod = NotCod,
.Icon = TL_Sha_ICON_SHARE,
.Title = Txt_TIMELINE_Share,
},
[true] = // I have shared ==> unshare
{
.Action = TL_Frm_UNS_NOTE,
.ParamFormat = "NotCod=%ld",
.ParamCod = NotCod,
.Icon = TL_Sha_ICON_SHARED,
.Title = Txt_TIMELINE_Shared,
},
}; };
static const char *Icon[2] =
{
TL_Sha_ICON_SHARE, // Not shared ==> put icon to share
TL_Sha_ICON_SHARED, // Shared ==> put icon to unshare
};
const char *Title[2] =
{
Txt_TIMELINE_Share, // Not shared ==> put text to share
Txt_TIMELINE_Shared, // Shared ==> put text to unshare
};
/***** Select whether share/unshare *****/
ShaUns = TL_Sha_CheckIfNoteIsSharedByUsr (NotCod,Gbl.Usrs.Me.UsrDat.UsrCod); // I have shared this note
/***** Form and icon to share/unshare note *****/ /***** Form and icon to share/unshare note *****/
TL_Frm_FormFavSha (Action[ShaUns],"NotCod=%ld",NotCod,Icon[ShaUns],Title[ShaUns]); TL_Frm_FormFavSha (&Form[TL_Sha_CheckIfNoteIsSharedByUsr (NotCod,Gbl.Usrs.Me.UsrDat.UsrCod)]);
} }
/*****************************************************************************/ /*****************************************************************************/