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:
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 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: 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: 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)

View File

@ -410,28 +410,28 @@ static void TL_Fav_PutFormToFavUnfNote (long NotCod)
{
extern const char *Txt_TIMELINE_Favourite;
extern const char *Txt_TIMELINE_Mark_as_favourite;
bool FavUnf;
static TL_Frm_Action_t Action[2] =
struct TL_Form Form[2] =
{
TL_Frm_FAV_NOTE, // Not faved ==> fav
TL_Frm_UNF_NOTE, // Faved ==> unfav
[false] = // I have not faved ==> fav
{
.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 *****/
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_Mark_as_favourite;
bool FavUnf;
static TL_Frm_Action_t Action[2] =
struct TL_Form Form[2] =
{
TL_Frm_FAV_COMM, // Not faved ==> fav
TL_Frm_UNF_COMM, // Faved ==> unfav
[false] = // I have not faved ==> fav
{
.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 *****/
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)
{
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)
{
case TL_Usr_SHOW_FEW_USRS:
/***** Form and icon to mark note as favourite *****/
TL_Frm_FormFavSha (Action,ParamFormat,ParamCod,
TL_Frm_ICON_ELLIPSIS,Txt_View_all_USERS);
/***** Form and icon to view all users *****/
TL_Frm_FormFavSha (&Form);
break;
case TL_Usr_SHOW_ALL_USRS:
/***** Disabled icon *****/
Ico_PutIconOff (TL_Frm_ICON_ELLIPSIS,Txt_View_all_USERS);
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 *******/
/*****************************************************************************/
void TL_Frm_FormFavSha (TL_Frm_Action_t Action,
const char *ParamFormat,long ParamCod,
const char *Icon,const char *Title)
void TL_Frm_FormFavSha (const struct TL_Form *Form)
{
char *OnSubmit;
char ParamStr[7 + Cns_MAX_DECIMAL_DIGITS_LONG + 1];
/***** 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,"
"'act=%ld&ses=%s&%s&OtherUsrCod=%s');"
" 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,
ParamStr,
Gbl.Usrs.Other.UsrDat.EnUsrCod) < 0)
@ -190,13 +196,13 @@ void TL_Frm_FormFavSha (TL_Frm_Action_t Action,
if (asprintf (&OnSubmit,"updateDivFaversSharers(this,"
"'act=%ld&ses=%s&%s');"
" 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,
ParamStr) < 0)
Lay_NotEnoughMemoryExit ();
Frm_StartFormUniqueAnchorOnSubmit (ActUnk,NULL,OnSubmit);
}
Ico_PutIconLink (Icon,Title);
Ico_PutIconLink (Form->Icon,Form->Title);
Frm_EndForm ();
/* Free allocated memory */

View File

@ -27,12 +27,6 @@
/********************************** Headers **********************************/
/*****************************************************************************/
// #include "swad_form.h"
// #include "swad_media.h"
// #include "swad_notification.h"
// #include "swad_user.h"
// #include "swad_timeline_user.h"
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
@ -70,6 +64,15 @@ typedef enum
TL_Frm_SHO_HID_COMM, // Show / hide comments
} 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 ****************************/
/*****************************************************************************/
@ -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,
const char *ParamFormat,long ParamCod,
TL_Usr_HowManyUsrs_t HowManyUsrs);
void TL_Frm_FormFavSha (TL_Frm_Action_t Action,
const char *ParamFormat,long ParamCod,
const char *Icon,const char *Title);
void TL_Frm_FormFavSha (const struct TL_Form *Form);
void TL_Frm_FormToShowHiddenComments (long NotCod,
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_Share;
bool ShaUns;
static TL_Frm_Action_t Action[2] =
struct TL_Form Form[2] =
{
TL_Frm_SHA_NOTE, // Not shared ==> share
TL_Frm_UNS_NOTE, // Shared ==> unshare
[false] = // I have not shared ==> share
{
.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 *****/
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)]);
}
/*****************************************************************************/