mirror of https://github.com/acanas/swad-core.git
Version 22.49.6: Oct 18, 2022 Code refactoring related to alerts.
This commit is contained in:
parent
fea76913bc
commit
11ddb85b10
76
swad_alert.c
76
swad_alert.c
|
@ -44,6 +44,24 @@
|
|||
|
||||
extern struct Globals Gbl;
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************* Private global variables **************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static struct
|
||||
{
|
||||
size_t Num; // Number of alert
|
||||
struct
|
||||
{
|
||||
Ale_AlertType_t Type;
|
||||
char *Text; // Message to be displayed
|
||||
char *Section; // Where to display the alert
|
||||
} List[Ale_MAX_ALERTS];
|
||||
} Ale_Alerts = // Alert message created in a function and printed in a subsequent function
|
||||
{
|
||||
.Num = 0, // No pending alerts to be shown
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Private prototypes ****************************/
|
||||
/*****************************************************************************/
|
||||
|
@ -66,23 +84,23 @@ void Ale_CreateAlert (Ale_AlertType_t Type,const char *Section,
|
|||
int NumBytesPrinted;
|
||||
size_t i;
|
||||
|
||||
if (Gbl.Alerts.Num + 1 > Ale_MAX_ALERTS)
|
||||
if (Ale_Alerts.Num + 1 > Ale_MAX_ALERTS)
|
||||
Err_ShowErrorAndExit ("Too many alerts.");
|
||||
|
||||
i = Gbl.Alerts.Num;
|
||||
Gbl.Alerts.Num++;
|
||||
i = Ale_Alerts.Num;
|
||||
Ale_Alerts.Num++;
|
||||
|
||||
Gbl.Alerts.List[i].Type = Type;
|
||||
Ale_Alerts.List[i].Type = Type;
|
||||
|
||||
Gbl.Alerts.List[i].Section = NULL;
|
||||
Ale_Alerts.List[i].Section = NULL;
|
||||
if (Section)
|
||||
if (Section[0])
|
||||
if (asprintf (&Gbl.Alerts.List[i].Section,"%s",
|
||||
if (asprintf (&Ale_Alerts.List[i].Section,"%s",
|
||||
Section) < 0)
|
||||
Err_NotEnoughMemoryExit ();
|
||||
|
||||
va_start (ap,fmt);
|
||||
NumBytesPrinted = vasprintf (&Gbl.Alerts.List[i].Text,fmt,ap);
|
||||
NumBytesPrinted = vasprintf (&Ale_Alerts.List[i].Text,fmt,ap);
|
||||
va_end (ap);
|
||||
if (NumBytesPrinted < 0) // -1 if no memory or any other error
|
||||
Err_NotEnoughMemoryExit ();
|
||||
|
@ -94,7 +112,7 @@ void Ale_CreateAlert (Ale_AlertType_t Type,const char *Section,
|
|||
|
||||
size_t Ale_GetNumAlerts (void)
|
||||
{
|
||||
return Gbl.Alerts.Num;
|
||||
return Ale_Alerts.Num;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -103,7 +121,7 @@ size_t Ale_GetNumAlerts (void)
|
|||
|
||||
Ale_AlertType_t Ale_GetTypeOfLastAlert (void)
|
||||
{
|
||||
return Gbl.Alerts.Num ? Gbl.Alerts.List[Gbl.Alerts.Num - 1].Type :
|
||||
return Ale_Alerts.Num ? Ale_Alerts.List[Ale_Alerts.Num - 1].Type :
|
||||
Ale_NONE;
|
||||
}
|
||||
|
||||
|
@ -113,7 +131,7 @@ Ale_AlertType_t Ale_GetTypeOfLastAlert (void)
|
|||
|
||||
const char *Ale_GetTextOfLastAlert (void)
|
||||
{
|
||||
return Gbl.Alerts.Num ? Gbl.Alerts.List[Gbl.Alerts.Num - 1].Text :
|
||||
return Ale_Alerts.Num ? Ale_Alerts.List[Ale_Alerts.Num - 1].Text :
|
||||
NULL;
|
||||
}
|
||||
|
||||
|
@ -126,7 +144,7 @@ void Ale_ResetAllAlerts (void)
|
|||
size_t NumAlert;
|
||||
|
||||
for (NumAlert = 0;
|
||||
NumAlert < Gbl.Alerts.Num;
|
||||
NumAlert < Ale_Alerts.Num;
|
||||
NumAlert++)
|
||||
Ale_ResetAlert (NumAlert);
|
||||
}
|
||||
|
@ -137,8 +155,8 @@ void Ale_ResetAllAlerts (void)
|
|||
|
||||
static void Ale_ResetLastAlert (void)
|
||||
{
|
||||
if (Gbl.Alerts.Num) // There are pending alerts not shown
|
||||
Ale_ResetAlert (Gbl.Alerts.Num - 1); // Reset the last one
|
||||
if (Ale_Alerts.Num) // There are pending alerts not shown
|
||||
Ale_ResetAlert (Ale_Alerts.Num - 1); // Reset the last one
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -150,24 +168,24 @@ static void Ale_ResetAlert (size_t NumAlert)
|
|||
bool NoMoreAlertsPending;
|
||||
size_t i;
|
||||
|
||||
if (NumAlert < Gbl.Alerts.Num)
|
||||
if (Gbl.Alerts.List[NumAlert].Type != Ale_NONE)
|
||||
if (NumAlert < Ale_Alerts.Num)
|
||||
if (Ale_Alerts.List[NumAlert].Type != Ale_NONE)
|
||||
{
|
||||
/***** Reset alert *****/
|
||||
Gbl.Alerts.List[NumAlert].Type = Ale_NONE; // Reset alert
|
||||
Ale_Alerts.List[NumAlert].Type = Ale_NONE; // Reset alert
|
||||
|
||||
/***** Free memory allocated for text *****/
|
||||
if (Gbl.Alerts.List[NumAlert].Text)
|
||||
if (Ale_Alerts.List[NumAlert].Text)
|
||||
{
|
||||
free (Gbl.Alerts.List[NumAlert].Text);
|
||||
Gbl.Alerts.List[NumAlert].Text = NULL;
|
||||
free (Ale_Alerts.List[NumAlert].Text);
|
||||
Ale_Alerts.List[NumAlert].Text = NULL;
|
||||
}
|
||||
|
||||
/***** Free memory allocated for section *****/
|
||||
if (Gbl.Alerts.List[NumAlert].Section)
|
||||
if (Ale_Alerts.List[NumAlert].Section)
|
||||
{
|
||||
free (Gbl.Alerts.List[NumAlert].Section);
|
||||
Gbl.Alerts.List[NumAlert].Section = NULL;
|
||||
free (Ale_Alerts.List[NumAlert].Section);
|
||||
Ale_Alerts.List[NumAlert].Section = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,13 +194,13 @@ static void Ale_ResetAlert (size_t NumAlert)
|
|||
pending to be shown *****/
|
||||
NoMoreAlertsPending = true;
|
||||
for (i = 0;
|
||||
NoMoreAlertsPending && i < Gbl.Alerts.Num;
|
||||
NoMoreAlertsPending && i < Ale_Alerts.Num;
|
||||
i++)
|
||||
if (Gbl.Alerts.List[i].Type != Ale_NONE)
|
||||
if (Ale_Alerts.List[i].Type != Ale_NONE)
|
||||
NoMoreAlertsPending = false;
|
||||
|
||||
if (NoMoreAlertsPending)
|
||||
Gbl.Alerts.Num = 0;
|
||||
Ale_Alerts.Num = 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -210,17 +228,17 @@ void Ale_ShowAlerts (const char *Section)
|
|||
for (NumAlert = 0;
|
||||
NumAlert < NumAlerts;
|
||||
NumAlert++)
|
||||
if (Gbl.Alerts.List[NumAlert].Type != Ale_NONE)
|
||||
if (Ale_Alerts.List[NumAlert].Type != Ale_NONE)
|
||||
{
|
||||
if (Section)
|
||||
ShowAlert = (bool) !strcmp (Gbl.Alerts.List[NumAlert].Section,Section);
|
||||
ShowAlert = (bool) !strcmp (Ale_Alerts.List[NumAlert].Section,Section);
|
||||
else
|
||||
ShowAlert = true;
|
||||
|
||||
if (ShowAlert)
|
||||
{
|
||||
Ale_ShowFixAlert (Gbl.Alerts.List[NumAlert].Type,
|
||||
Gbl.Alerts.List[NumAlert].Text);
|
||||
Ale_ShowFixAlert (Ale_Alerts.List[NumAlert].Type,
|
||||
Ale_Alerts.List[NumAlert].Text);
|
||||
Ale_ResetAlert (NumAlert);
|
||||
}
|
||||
}
|
||||
|
|
29
swad_box.c
29
swad_box.c
|
@ -47,7 +47,7 @@ static struct
|
|||
{
|
||||
int Nested; // Index of top open box
|
||||
char *Ids[Box_MAX_NESTED]; // 0 <= box index < Box_MAX_NESTED
|
||||
} Box =
|
||||
} Box_Boxes =
|
||||
{
|
||||
.Nested = -1, // -1 means no box open
|
||||
};
|
||||
|
@ -130,28 +130,29 @@ static void Box_BoxInternalBegin (const char *Width,const char *Title,
|
|||
extern const char *Txt_Close;
|
||||
|
||||
/***** Check level of nesting *****/
|
||||
if (Box.Nested >= Box_MAX_NESTED - 1) // Can not nest a new box
|
||||
if (Box_Boxes.Nested >= Box_MAX_NESTED - 1) // Can not nest a new box
|
||||
Err_ShowErrorAndExit ("Box nesting limit reached.");
|
||||
|
||||
/***** Increase level of nesting *****/
|
||||
Box.Nested++;
|
||||
Box_Boxes.Nested++;
|
||||
|
||||
/***** Create unique identifier for this box *****/
|
||||
if (Closable == Box_CLOSABLE)
|
||||
{
|
||||
if ((Box.Ids[Box.Nested] = malloc (Frm_MAX_BYTES_ID + 1)) == NULL)
|
||||
if ((Box_Boxes.Ids[Box_Boxes.Nested] = malloc (Frm_MAX_BYTES_ID + 1)) == NULL)
|
||||
Err_NotEnoughMemoryExit ();
|
||||
}
|
||||
else
|
||||
Box.Ids[Box.Nested] = NULL;
|
||||
Box_Boxes.Ids[Box_Boxes.Nested] = NULL;
|
||||
|
||||
/***** Begin box container *****/
|
||||
if (Closable == Box_CLOSABLE)
|
||||
{
|
||||
/* Create unique id for alert */
|
||||
Frm_SetUniqueId (Box.Ids[Box.Nested]);
|
||||
Frm_SetUniqueId (Box_Boxes.Ids[Box_Boxes.Nested]);
|
||||
|
||||
HTM_DIV_Begin ("class=\"FRAME_CONT\" id=\"%s\"",Box.Ids[Box.Nested]);
|
||||
HTM_DIV_Begin ("class=\"FRAME_CONT\" id=\"%s\"",
|
||||
Box_Boxes.Ids[Box_Boxes.Nested]);
|
||||
}
|
||||
else
|
||||
HTM_DIV_Begin ("class=\"FRAME_CONT\"");
|
||||
|
@ -192,7 +193,7 @@ static void Box_BoxInternalBegin (const char *Width,const char *Title,
|
|||
if (Closable == Box_CLOSABLE) // Icon to close the box
|
||||
{
|
||||
HTM_A_Begin ("href=\"\" onclick=\"toggleDisplay('%s');return false;\"",
|
||||
Box.Ids[Box.Nested]);
|
||||
Box_Boxes.Ids[Box_Boxes.Nested]);
|
||||
Ico_PutDivIcon ("CONTEXT_OPT HLP_HIGHLIGHT",
|
||||
"times.svg",Ico_BLACK,Txt_Close);
|
||||
HTM_A_End ();
|
||||
|
@ -208,8 +209,8 @@ static void Box_BoxInternalBegin (const char *Width,const char *Title,
|
|||
if (Title)
|
||||
{
|
||||
HTM_DIV_Begin ("class=\"FRAME_TITLE %s FRAME_TITLE_%s\"",
|
||||
Box.Nested ? "FRAME_TITLE_SMALL" :
|
||||
"FRAME_TITLE_BIG",
|
||||
Box_Boxes.Nested ? "FRAME_TITLE_SMALL" :
|
||||
"FRAME_TITLE_BIG",
|
||||
The_GetSuffix ());
|
||||
HTM_Txt (Title);
|
||||
HTM_DIV_End ();
|
||||
|
@ -237,17 +238,17 @@ void Box_BoxWithButtonEnd (Btn_Button_t Button,const char *TxtButton)
|
|||
void Box_BoxEnd (void)
|
||||
{
|
||||
/***** Check level of nesting *****/
|
||||
if (Box.Nested < 0)
|
||||
if (Box_Boxes.Nested < 0)
|
||||
Err_ShowErrorAndExit ("Trying to end a box not open.");
|
||||
|
||||
/***** Free memory allocated for box id string *****/
|
||||
if (Box.Ids[Box.Nested])
|
||||
free (Box.Ids[Box.Nested]);
|
||||
if (Box_Boxes.Ids[Box_Boxes.Nested])
|
||||
free (Box_Boxes.Ids[Box_Boxes.Nested]);
|
||||
|
||||
/***** End box and box container *****/
|
||||
HTM_DIV_End ();
|
||||
HTM_DIV_End ();
|
||||
|
||||
/***** Decrease level of nesting *****/
|
||||
Box.Nested--;
|
||||
Box_Boxes.Nested--;
|
||||
}
|
||||
|
|
|
@ -606,10 +606,11 @@ TODO: Fix bug: error al enviar un mensaje a dos recipientes, error on duplicate
|
|||
|
||||
TODO: Attach pdf files in multimedia.
|
||||
*/
|
||||
#define Log_PLATFORM_VERSION "SWAD 22.49.5 (2022-10-18)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 22.49.6 (2022-10-18)"
|
||||
#define CSS_FILE "swad22.49.4.css"
|
||||
#define JS_FILE "swad22.49.js"
|
||||
/*
|
||||
Version 22.49.6: Oct 18, 2022 Code refactoring related to alerts. (333197 lines)
|
||||
Version 22.49.5: Oct 18, 2022 Code refactoring related to boxes. (333190 lines)
|
||||
Version 22.49.4: Oct 18, 2022 Lighter background colors in tables.
|
||||
Changes in responsive layout. (333187 lines)
|
||||
|
|
|
@ -106,8 +106,6 @@ void Gbl_InitializeGlobals (void)
|
|||
Gbl.F.XML = NULL;
|
||||
Gbl.F.Rep = NULL; // Report
|
||||
|
||||
Gbl.Alerts.Num = 0; // No pending alerts to be shown
|
||||
|
||||
Gbl.DB.DatabaseIsOpen = false;
|
||||
Gbl.DB.LockedTables = false;
|
||||
|
||||
|
|
|
@ -74,16 +74,6 @@ struct Globals
|
|||
} Config;
|
||||
struct Files F;
|
||||
pid_t PID; // PID of current process
|
||||
struct
|
||||
{
|
||||
size_t Num; // Number of alert
|
||||
struct
|
||||
{
|
||||
Ale_AlertType_t Type;
|
||||
char *Text; // Message to be displayed
|
||||
char *Section; // Where to display the alert
|
||||
} List[Ale_MAX_ALERTS];
|
||||
} Alerts; // Alert message created in a function and printed in a subsequent function.
|
||||
struct
|
||||
{
|
||||
size_t ContentLength;
|
||||
|
|
Loading…
Reference in New Issue