From 833db9aa2a511169d3872f92e67b2b047cb4be64 Mon Sep 17 00:00:00 2001 From: acanas Date: Mon, 8 Feb 2021 20:16:00 +0100 Subject: [PATCH] Version20.14.2 --- swad_changelog.h | 3 +- swad_timeline.c | 142 +++++++++++++++++++++++--------------- swad_timeline.h | 10 +-- swad_timeline_favourite.c | 94 ++++++++----------------- swad_timeline_favourite.h | 4 +- swad_timeline_share.c | 47 ++++--------- swad_timeline_share.h | 3 - 7 files changed, 135 insertions(+), 168 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index d2d1d391c..301758368 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -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.14.1 (2021-02-08)" +#define Log_PLATFORM_VERSION "SWAD 20.14.2 (2021-02-08)" #define CSS_FILE "swad20.8.css" #define JS_FILE "swad20.6.2.js" /* @@ -600,6 +600,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. + Version 20.14.2: Feb 08, 2021 Code refactoring in timeline. (305044 lines) Version 20.14.1: Feb 08, 2021 Code refactoring in timeline. (305072 lines) Version 20.14: Feb 08, 2021 New module timeline_shared. (305048 lines) Version 20.13: Feb 08, 2021 New module timeline_favourite. (304971 lines) diff --git a/swad_timeline.c b/swad_timeline.c index b0471dd91..8631ec328 100644 --- a/swad_timeline.c +++ b/swad_timeline.c @@ -1184,63 +1184,6 @@ static void TL_FormStart (const struct TL_Timeline *Timeline, } } -/*****************************************************************************/ -/******* Form to fav/unfav or share/unshare in global or user timeline *******/ -/*****************************************************************************/ - -void TL_FormFavSha (Act_Action_t ActionGbl,Act_Action_t ActionUsr, - const char *ParamCod, - const char *Icon,const char *Title) - { - char *OnSubmit; - - /* - +---------------------------------------------------------------------------+ - | div which content will be updated (parent of parent of form) | - | +---------------------+ +-------+ +-------------------------------------+ | - | | div (parent of form)| | div | | div for users | | - | | +-----------------+ | | for | | +------+ +------+ +------+ +------+ | | - | | | this form | | | num. | | | | | | | | | form | | | - | | | +-------------+ | | | of | | | user | | user | | user | | to | | | - | | | | fav icon | | | | users | | | 1 | | 2 | | 3 | | show | | | - | | | +-------------+ | | | | | | | | | | | | all | | | - | | +-----------------+ | | | | +------+ +------+ +------+ +------+ | | - | +---------------------+ +-------+ +-------------------------------------+ | - +---------------------------------------------------------------------------+ - */ - - /***** Form and icon to mark note as favourite *****/ - /* Form with icon */ - if (Gbl.Usrs.Other.UsrDat.UsrCod > 0) - { - if (asprintf (&OnSubmit,"updateDivFaversSharers(this," - "'act=%ld&ses=%s&%s&OtherUsrCod=%s');" - " return false;", // return false is necessary to not submit form - Act_GetActCod (ActionUsr), - Gbl.Session.Id, - ParamCod, - Gbl.Usrs.Other.UsrDat.EncryptedUsrCod) < 0) - Lay_NotEnoughMemoryExit (); - Frm_StartFormUniqueAnchorOnSubmit (ActUnk,"timeline",OnSubmit); - } - else - { - if (asprintf (&OnSubmit,"updateDivFaversSharers(this," - "'act=%ld&ses=%s&%s');" - " return false;", // return false is necessary to not submit form - Act_GetActCod (ActionGbl), - Gbl.Session.Id, - ParamCod) < 0) - Lay_NotEnoughMemoryExit (); - Frm_StartFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit); - } - Ico_PutIconLink (Icon,Title); - Frm_EndForm (); - - /* Free allocated memory */ - free (OnSubmit); - } - /*****************************************************************************/ /******** Show form to select users whom public activity is displayed ********/ /*****************************************************************************/ @@ -4099,6 +4042,91 @@ void TL_ShowSharersOrFavers (MYSQL_RES **mysql_res, } } +/*****************************************************************************/ +/********************* Form to show all favers/sharers ***********************/ +/*****************************************************************************/ + +void TL_PutFormToSeeAllFaversSharers (Act_Action_t ActionGbl,Act_Action_t ActionUsr, + const char *ParamFormat,long ParamCod, + TL_HowManyUsrs_t HowManyUsrs) + { + extern const char *Txt_View_all_USERS; + + switch (HowManyUsrs) + { + case TL_SHOW_FEW_USRS: + /***** Form and icon to mark note as favourite *****/ + TL_FormFavSha (ActionGbl,ActionUsr, + ParamFormat,ParamCod, + TL_ICON_ELLIPSIS,Txt_View_all_USERS); + break; + case TL_SHOW_ALL_USRS: + Ico_PutIconOff (TL_ICON_ELLIPSIS,Txt_View_all_USERS); + break; + } + } + +/*****************************************************************************/ +/******* Form to fav/unfav or share/unshare in global or user timeline *******/ +/*****************************************************************************/ + +void TL_FormFavSha (Act_Action_t ActionGbl,Act_Action_t ActionUsr, + const char *ParamFormat,long ParamCod, + const char *Icon,const char *Title) + { + char *OnSubmit; + char ParamStr[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; + + /***** Create parameter string *****/ + sprintf (ParamStr,ParamFormat,ParamCod); + + /* + +---------------------------------------------------------------------------+ + | div which content will be updated (parent of parent of form) | + | +---------------------+ +-------+ +-------------------------------------+ | + | | div (parent of form)| | div | | div for users | | + | | +-----------------+ | | for | | +------+ +------+ +------+ +------+ | | + | | | this form | | | num. | | | | | | | | | form | | | + | | | +-------------+ | | | of | | | user | | user | | user | | to | | | + | | | | fav icon | | | | users | | | 1 | | 2 | | 3 | | show | | | + | | | +-------------+ | | | | | | | | | | | | all | | | + | | +-----------------+ | | | | +------+ +------+ +------+ +------+ | | + | +---------------------+ +-------+ +-------------------------------------+ | + +---------------------------------------------------------------------------+ + */ + + /***** Form and icon to mark note as favourite *****/ + /* Form with icon */ + if (Gbl.Usrs.Other.UsrDat.UsrCod > 0) + { + if (asprintf (&OnSubmit,"updateDivFaversSharers(this," + "'act=%ld&ses=%s&%s&OtherUsrCod=%s');" + " return false;", // return false is necessary to not submit form + Act_GetActCod (ActionUsr), + Gbl.Session.Id, + ParamStr, + Gbl.Usrs.Other.UsrDat.EncryptedUsrCod) < 0) + Lay_NotEnoughMemoryExit (); + Frm_StartFormUniqueAnchorOnSubmit (ActUnk,"timeline",OnSubmit); + } + else + { + if (asprintf (&OnSubmit,"updateDivFaversSharers(this," + "'act=%ld&ses=%s&%s');" + " return false;", // return false is necessary to not submit form + Act_GetActCod (ActionGbl), + Gbl.Session.Id, + ParamStr) < 0) + Lay_NotEnoughMemoryExit (); + Frm_StartFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit); + } + Ico_PutIconLink (Icon,Title); + Frm_EndForm (); + + /* Free allocated memory */ + free (OnSubmit); + } + /*****************************************************************************/ /******************** Get data of note using its code ************************/ /*****************************************************************************/ diff --git a/swad_timeline.h b/swad_timeline.h index 0ecba5e74..670e1f80b 100644 --- a/swad_timeline.h +++ b/swad_timeline.h @@ -163,10 +163,6 @@ void TL_RefreshOldTimelineUsr (void); void TL_MarkMyNotifAsSeen (void); -void TL_FormFavSha (Act_Action_t ActionGbl,Act_Action_t ActionUsr, - const char *ParamCod, - const char *Icon,const char *Title); - void TL_GetParamWho (void); Usr_Who_t TL_GetGlobalWho (void); @@ -210,6 +206,12 @@ void TL_RemoveUsrContent (long UsrCod); void TL_ShowNumSharersOrFavers (unsigned NumUsrs); void TL_ShowSharersOrFavers (MYSQL_RES **mysql_res, unsigned NumUsrs,unsigned NumFirstUsrs); +void TL_PutFormToSeeAllFaversSharers (Act_Action_t ActionGbl,Act_Action_t ActionUsr, + const char *ParamFormat,long ParamCod, + TL_HowManyUsrs_t HowManyUsrs); +void TL_FormFavSha (Act_Action_t ActionGbl,Act_Action_t ActionUsr, + const char *ParamFormat,long ParamCod, + const char *Icon,const char *Title); void TL_GetDataOfNoteByCod (struct TL_Note *SocNot); void TL_GetDataOfCommByCod (struct TL_Comment *SocCom); diff --git a/swad_timeline_favourite.c b/swad_timeline_favourite.c index ba789254c..388cd4121 100644 --- a/swad_timeline_favourite.c +++ b/swad_timeline_favourite.c @@ -57,11 +57,11 @@ extern struct Globals Gbl; static void TL_Fav_PutDisabledIconFav (unsigned NumFavs); -static void TL_Fav_PutFormToFavNote (const struct TL_Note *SocNot); -static void TL_Fav_PutFormToUnfNote (const struct TL_Note *SocNot); +static void TL_Fav_PutFormToFavNote (long ParamCod); +static void TL_Fav_PutFormToUnfNote (long ParamCod); -static void TL_Fav_PutFormToFavComment (const struct TL_Comment *SocCom); -static void TL_Fav_PutFormToUnfComment (const struct TL_Comment *SocCom); +static void TL_Fav_PutFormToFavComment (long ParamCod); +static void TL_Fav_PutFormToUnfComment (long ParamCod); static void TL_Fav_FavNote (struct TL_Note *SocNot); static void TL_Fav_UnfNote (struct TL_Note *SocNot); @@ -100,48 +100,26 @@ static void TL_Fav_PutDisabledIconFav (unsigned NumFavs) } /*****************************************************************************/ -/************************ Form to show all favers ****************************/ +/************************** Form to fav/unfav note ***************************/ /*****************************************************************************/ -void TL_Fav_PutFormToSeeAllFaversNote (const struct TL_Note *SocNot, - TL_HowManyUsrs_t HowManyUsrs) - { - extern const char *Txt_View_all_USERS; - char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; - - switch (HowManyUsrs) - { - case TL_SHOW_FEW_USRS: - /***** Form and icon to mark note as favourite *****/ - sprintf (ParamCod,"NotCod=%ld",SocNot->NotCod); - TL_FormFavSha (ActAllFavSocNotGbl,ActAllFavSocNotUsr,ParamCod, - TL_ICON_ELLIPSIS,Txt_View_all_USERS); - break; - case TL_SHOW_ALL_USRS: - Ico_PutIconOff (TL_ICON_ELLIPSIS,Txt_View_all_USERS); - break; - } - } - -static void TL_Fav_PutFormToFavNote (const struct TL_Note *SocNot) +static void TL_Fav_PutFormToFavNote (long ParamCod) { extern const char *Txt_Mark_as_favourite; - char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; /***** Form and icon to mark note as favourite *****/ - sprintf (ParamCod,"NotCod=%ld",SocNot->NotCod); - TL_FormFavSha (ActFavSocNotGbl,ActFavSocNotUsr,ParamCod, + TL_FormFavSha (ActFavSocNotGbl,ActFavSocNotUsr, + "NotCod=%ld",ParamCod, TL_ICON_FAV,Txt_Mark_as_favourite); } -static void TL_Fav_PutFormToUnfNote (const struct TL_Note *SocNot) +static void TL_Fav_PutFormToUnfNote (long ParamCod) { extern const char *Txt_TIMELINE_NOTE_Favourite; - char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; /***** Form and icon to unfav (remove mark as favourite) note *****/ - sprintf (ParamCod,"NotCod=%ld",SocNot->NotCod); - TL_FormFavSha (ActUnfSocNotGbl,ActUnfSocNotUsr,ParamCod, + TL_FormFavSha (ActUnfSocNotGbl,ActUnfSocNotUsr, + "NotCod=%ld",ParamCod, TL_ICON_FAVED,Txt_TIMELINE_NOTE_Favourite); } @@ -149,45 +127,23 @@ static void TL_Fav_PutFormToUnfNote (const struct TL_Note *SocNot) /************************** Form to fav/unfav comment ************************/ /*****************************************************************************/ -void TL_Fav_PutFormToSeeAllFaversComment (const struct TL_Comment *SocCom, - TL_HowManyUsrs_t HowManyUsrs) - { - extern const char *Txt_View_all_USERS; - char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; - - switch (HowManyUsrs) - { - case TL_SHOW_FEW_USRS: - /***** Form and icon to mark comment as favourite *****/ - sprintf (ParamCod,"PubCod=%ld",SocCom->PubCod); - TL_FormFavSha (ActAllFavSocComGbl,ActAllFavSocComUsr,ParamCod, - TL_ICON_ELLIPSIS,Txt_View_all_USERS); - break; - case TL_SHOW_ALL_USRS: - Ico_PutIconOff (TL_ICON_ELLIPSIS,Txt_View_all_USERS); - break; - } - } - -static void TL_Fav_PutFormToFavComment (const struct TL_Comment *SocCom) +static void TL_Fav_PutFormToFavComment (long ParamCod) { extern const char *Txt_Mark_as_favourite; - char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; /***** Form and icon to mark comment as favourite *****/ - sprintf (ParamCod,"PubCod=%ld",SocCom->PubCod); - TL_FormFavSha (ActFavSocComGbl,ActFavSocComUsr,ParamCod, + TL_FormFavSha (ActFavSocComGbl,ActFavSocComUsr, + "PubCod=%ld",ParamCod, TL_ICON_FAV,Txt_Mark_as_favourite); } -static void TL_Fav_PutFormToUnfComment (const struct TL_Comment *SocCom) +static void TL_Fav_PutFormToUnfComment (long ParamCod) { extern const char *Txt_TIMELINE_NOTE_Favourite; - char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; /***** Form and icon to unfav (remove mark as favourite) comment *****/ - sprintf (ParamCod,"PubCod=%ld",SocCom->PubCod); - TL_FormFavSha (ActUnfSocComGbl,ActUnfSocComUsr,ParamCod, + TL_FormFavSha (ActUnfSocComGbl,ActUnfSocComUsr, + "PubCod=%ld",ParamCod, TL_ICON_FAVED,Txt_TIMELINE_NOTE_Favourite); } @@ -275,9 +231,9 @@ void TL_Fav_PutFormToFavUnfNote (const struct TL_Note *SocNot, IAmAFaverOfThisSocNot = TL_Fav_CheckIfNoteIsFavedByUsr (SocNot->NotCod, Gbl.Usrs.Me.UsrDat.UsrCod); if (IAmAFaverOfThisSocNot) // I have favourited this note - TL_Fav_PutFormToUnfNote (SocNot); + TL_Fav_PutFormToUnfNote (SocNot->NotCod); else // I am not a faver of this note - TL_Fav_PutFormToFavNote (SocNot); + TL_Fav_PutFormToFavNote (SocNot->NotCod); } HTM_DIV_End (); @@ -443,10 +399,10 @@ void TL_Fav_PutFormToFavUnfComment (const struct TL_Comment *SocCom, Gbl.Usrs.Me.UsrDat.UsrCod); if (IAmAFaverOfThisSocCom) // I have favourited this comment /* Put icon to unfav this publication and list of users */ - TL_Fav_PutFormToUnfComment (SocCom); + TL_Fav_PutFormToUnfComment (SocCom->PubCod); else // I am not a favouriter /* Put icon to fav this publication and list of users */ - TL_Fav_PutFormToFavComment (SocCom); + TL_Fav_PutFormToFavComment (SocCom->PubCod); } HTM_DIV_End (); @@ -629,7 +585,9 @@ static void TL_Fav_ShowUsrsWhoHaveMarkedNoteAsFav (const struct TL_Note *SocNot, TL_ShowSharersOrFavers (&mysql_res,SocNot->NumFavs,NumFirstUsrs); if (NumFirstUsrs < SocNot->NumFavs) // Not all are shown /* Clickable ellipsis to show all users */ - TL_Fav_PutFormToSeeAllFaversNote (SocNot,HowManyUsrs); + TL_PutFormToSeeAllFaversSharers (ActAllFavSocNotGbl,ActAllFavSocNotUsr, + "NotCod=%ld",SocNot->NotCod, + HowManyUsrs); HTM_DIV_End (); /***** Free structure that stores the query result *****/ @@ -674,7 +632,9 @@ static void TL_Fav_ShowUsrsWhoHaveMarkedCommAsFav (const struct TL_Comment *SocC TL_ShowSharersOrFavers (&mysql_res,SocCom->NumFavs,NumFirstUsrs); if (NumFirstUsrs < SocCom->NumFavs) /* Clickable ellipsis to show all users */ - TL_Fav_PutFormToSeeAllFaversComment (SocCom,HowManyUsrs); + TL_PutFormToSeeAllFaversSharers (ActAllFavSocComGbl,ActAllFavSocComUsr, + "PubCod=%ld",SocCom->PubCod, + HowManyUsrs); HTM_DIV_End (); /***** Free structure that stores the query result *****/ diff --git a/swad_timeline_favourite.h b/swad_timeline_favourite.h index 653c695c8..604902b85 100644 --- a/swad_timeline_favourite.h +++ b/swad_timeline_favourite.h @@ -39,9 +39,9 @@ /****************************** Public prototypes ****************************/ /*****************************************************************************/ -void TL_Fav_PutFormToSeeAllFaversNote (const struct TL_Note *SocNot, +void TL_Fav_PutFormToSeeAllFaversNote (long NotCod, TL_HowManyUsrs_t HowManyUsrs); -void TL_Fav_PutFormToSeeAllFaversComment (const struct TL_Comment *SocCom, +void TL_Fav_PutFormToSeeAllFaversComment (long PubCod, TL_HowManyUsrs_t HowManyUsrs); void TL_Fav_ShowAllFaversNoteUsr (void); diff --git a/swad_timeline_share.c b/swad_timeline_share.c index 87320f592..4f3627276 100644 --- a/swad_timeline_share.c +++ b/swad_timeline_share.c @@ -57,8 +57,8 @@ extern struct Globals Gbl; static void TL_Sha_PutDisabledIconShare (unsigned NumShared); -static void TL_Sha_PutFormToShaNote (const struct TL_Note *SocNot); -static void TL_Sha_PutFormToUnsNote (const struct TL_Note *SocNot); +static void TL_Sha_PutFormToShaNote (long ParamCod); +static void TL_Sha_PutFormToUnsNote (long ParamCod); static void TL_Sha_ShaNote (struct TL_Note *SocNot); static void TL_Sha_UnsNote (struct TL_Note *SocNot); @@ -94,45 +94,23 @@ static void TL_Sha_PutDisabledIconShare (unsigned NumShared) /*********************** Form to share/unshare note **************************/ /*****************************************************************************/ -void TL_Sha_PutFormToSeeAllSharersNote (const struct TL_Note *SocNot, - TL_HowManyUsrs_t HowManyUsrs) - { - extern const char *Txt_View_all_USERS; - char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; - - switch (HowManyUsrs) - { - case TL_SHOW_FEW_USRS: - /***** Form and icon to mark note as favourite *****/ - sprintf (ParamCod,"NotCod=%ld",SocNot->NotCod); - TL_FormFavSha (ActAllShaSocNotGbl,ActAllShaSocNotUsr,ParamCod, - TL_ICON_ELLIPSIS,Txt_View_all_USERS); - break; - case TL_SHOW_ALL_USRS: - Ico_PutIconOff (TL_ICON_ELLIPSIS,Txt_View_all_USERS); - break; - } - } - -static void TL_Sha_PutFormToShaNote (const struct TL_Note *SocNot) +static void TL_Sha_PutFormToShaNote (long ParamCod) { extern const char *Txt_Share; - char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; /***** Form and icon to mark note as favourite *****/ - sprintf (ParamCod,"NotCod=%ld",SocNot->NotCod); - TL_FormFavSha (ActShaSocNotGbl,ActShaSocNotUsr,ParamCod, + TL_FormFavSha (ActShaSocNotGbl,ActShaSocNotUsr, + "NotCod=%ld",ParamCod, TL_ICON_SHARE,Txt_Share); } -static void TL_Sha_PutFormToUnsNote (const struct TL_Note *SocNot) +static void TL_Sha_PutFormToUnsNote (long ParamCod) { extern const char *Txt_TIMELINE_NOTE_Shared; - char ParamCod[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1]; /***** Form and icon to mark note as favourite *****/ - sprintf (ParamCod,"NotCod=%ld",SocNot->NotCod); - TL_FormFavSha (ActUnsSocNotGbl,ActUnsSocNotUsr,ParamCod, + TL_FormFavSha (ActUnsSocNotGbl,ActUnsSocNotUsr, + "NotCod=%ld",ParamCod, TL_ICON_SHARED,Txt_TIMELINE_NOTE_Shared); } @@ -299,9 +277,9 @@ void TL_Sha_PutFormToShaUnsNote (const struct TL_Note *SocNot, IAmASharerOfThisSocNot = TL_Sha_CheckIfNoteIsSharedByUsr (SocNot->NotCod, Gbl.Usrs.Me.UsrDat.UsrCod); if (IAmASharerOfThisSocNot) // I have shared this note - TL_Sha_PutFormToUnsNote (SocNot); + TL_Sha_PutFormToUnsNote (SocNot->NotCod); else // I have not shared this note - TL_Sha_PutFormToShaNote (SocNot); + TL_Sha_PutFormToShaNote (SocNot->NotCod); } HTM_DIV_End (); @@ -382,11 +360,12 @@ static void TL_Sha_ShowUsrsWhoHaveSharedNote (const struct TL_Note *SocNot, TL_ShowSharersOrFavers (&mysql_res,SocNot->NumShared,NumFirstUsrs); if (NumFirstUsrs < SocNot->NumShared) /* Clickable ellipsis to show all users */ - TL_Sha_PutFormToSeeAllSharersNote (SocNot,HowManyUsrs); + TL_PutFormToSeeAllFaversSharers (ActAllShaSocNotGbl,ActAllShaSocNotUsr, + "NotCod=%ld",SocNot->NotCod, + HowManyUsrs); HTM_DIV_End (); /***** Free structure that stores the query result *****/ if (SocNot->NumShared) DB_FreeMySQLResult (&mysql_res); } - diff --git a/swad_timeline_share.h b/swad_timeline_share.h index 54ff0ccc6..f514157d1 100644 --- a/swad_timeline_share.h +++ b/swad_timeline_share.h @@ -39,9 +39,6 @@ /****************************** Public prototypes ****************************/ /*****************************************************************************/ -void TL_Sha_PutFormToSeeAllSharersNote (const struct TL_Note *SocNot, - TL_HowManyUsrs_t HowManyUsrs); - void TL_Sha_ShowAllSharersNoteUsr (void); void TL_Sha_ShowAllSharersNoteGbl (void); void TL_Sha_ShaNoteUsr (void);