Fossil SCM
Improvements to handling of the cookie for "sticky" display settings.
Commit
3ec843970d10dc705150b76e9c2db4f8044504467c2d4317d71b492c4fd2d825
Parent
f64fa4f1ae38fe9…
2 files changed
+34
-8
+5
-4
+34
-8
| --- src/cookies.c | ||
| +++ src/cookies.c | ||
| @@ -54,10 +54,15 @@ | ||
| 54 | 54 | */ |
| 55 | 55 | #include "cookies.h" |
| 56 | 56 | #include <assert.h> |
| 57 | 57 | #include <string.h> |
| 58 | 58 | |
| 59 | +#if INTERFACE | |
| 60 | +/* the standard name of the display settings cookie for fossil */ | |
| 61 | +# define DISPLAY_SETTINGS_COOKIE "fossil_display_settings" | |
| 62 | +#endif | |
| 63 | + | |
| 59 | 64 | |
| 60 | 65 | /* |
| 61 | 66 | ** State information private to this module |
| 62 | 67 | */ |
| 63 | 68 | #define COOKIE_NPARAM 10 |
| @@ -105,19 +110,25 @@ | ||
| 105 | 110 | } |
| 106 | 111 | } |
| 107 | 112 | |
| 108 | 113 | #define COOKIE_READ 1 |
| 109 | 114 | #define COOKIE_WRITE 2 |
| 110 | -static void cookie_readwrite(const char *zQP, const char *zPName, int flags){ | |
| 115 | +static void cookie_readwrite( | |
| 116 | + const char *zQP, /* Name of the query parameter */ | |
| 117 | + const char *zPName, /* Name of the cooking setting */ | |
| 118 | + const char *zDflt, /* Default value for the query parameter */ | |
| 119 | + int flags /* READ or WRITE or both */ | |
| 120 | +){ | |
| 111 | 121 | const char *zQVal = P(zQP); |
| 112 | 122 | int i; |
| 113 | 123 | assert( cookies.zCookieName!=0 ); |
| 114 | 124 | for(i=0; i<cookies.nParam && strcmp(zPName,cookies.aParam[i].zPName); i++){} |
| 115 | - if( (flags & COOKIE_READ)!=0 && zQVal==0 && i<cookies.nParam ){ | |
| 125 | + if( zQVal==0 && (flags & COOKIE_READ)!=0 && i<cookies.nParam ){ | |
| 116 | 126 | cgi_set_parameter_nocopy(zQP, cookies.aParam[i].zPValue, 1); |
| 117 | 127 | return; |
| 118 | 128 | } |
| 129 | + if( zQVal==0 ) zQVal = zDflt; | |
| 119 | 130 | if( (flags & COOKIE_WRITE)!=0 |
| 120 | 131 | && i<COOKIE_NPARAM |
| 121 | 132 | && (i==cookies.nParam || strcmp(zQVal, cookies.aParam[i].zPValue)) |
| 122 | 133 | ){ |
| 123 | 134 | if( i==cookies.nParam ){ |
| @@ -131,25 +142,33 @@ | ||
| 131 | 142 | |
| 132 | 143 | /* If query parameter zQP is missing, initialize it using the zPName |
| 133 | 144 | ** value from the user preferences cookie |
| 134 | 145 | */ |
| 135 | 146 | void cookie_read_parameter(const char *zQP, const char *zPName){ |
| 136 | - cookie_readwrite(zQP, zPName, COOKIE_READ); | |
| 147 | + cookie_readwrite(zQP, zPName, 0, COOKIE_READ); | |
| 137 | 148 | } |
| 138 | 149 | |
| 139 | 150 | /* Update the zPName value of the user preference cookie to match |
| 140 | 151 | ** the value of query parameter zQP. |
| 141 | 152 | */ |
| 142 | -void cookie_write_parameter(const char *zQP, const char *zPName){ | |
| 143 | - cookie_readwrite(zQP, zPName, COOKIE_WRITE); | |
| 153 | +void cookie_write_parameter( | |
| 154 | + const char *zQP, | |
| 155 | + const char *zPName, | |
| 156 | + const char *zDflt | |
| 157 | +){ | |
| 158 | + cookie_readwrite(zQP, zPName, zDflt, COOKIE_WRITE); | |
| 144 | 159 | } |
| 145 | 160 | |
| 146 | 161 | /* Use the zPName user preference value as a default for zQP and record |
| 147 | 162 | ** any changes to the zQP value back into the cookie. |
| 148 | 163 | */ |
| 149 | -void cookie_link_parameter(const char *zQP, const char *zPName){ | |
| 150 | - cookie_readwrite(zQP, zPName, COOKIE_READ|COOKIE_WRITE); | |
| 164 | +void cookie_link_parameter( | |
| 165 | + const char *zQP, /* The query parameter */ | |
| 166 | + const char *zPName, /* The name of the cookie value */ | |
| 167 | + const char *zDflt /* Default value for the parameter */ | |
| 168 | +){ | |
| 169 | + cookie_readwrite(zQP, zPName, zDflt, COOKIE_READ|COOKIE_WRITE); | |
| 151 | 170 | } |
| 152 | 171 | |
| 153 | 172 | /* Update the user preferences cookie, if necessary, and shut down this |
| 154 | 173 | ** module |
| 155 | 174 | */ |
| @@ -175,12 +194,19 @@ | ||
| 175 | 194 | ** Show the current display settings contained in the |
| 176 | 195 | ** "fossil_display_settings" cookie. |
| 177 | 196 | */ |
| 178 | 197 | void cookie_page(void){ |
| 179 | 198 | int i; |
| 180 | - cookie_parse("fossil_display_settings"); | |
| 199 | + if( PB("clear") ){ | |
| 200 | + cgi_set_cookie(DISPLAY_SETTINGS_COOKIE, "", 0, 1); | |
| 201 | + cgi_replace_parameter(DISPLAY_SETTINGS_COOKIE, ""); | |
| 202 | + } | |
| 203 | + cookie_parse(DISPLAY_SETTINGS_COOKIE); | |
| 181 | 204 | style_header("User Preference Cookie Values"); |
| 205 | + if( cookies.nParam ){ | |
| 206 | + style_submenu_element("Clear", "%R/cookies?clear"); | |
| 207 | + } | |
| 182 | 208 | @ <p>The following are user preference settings held in the |
| 183 | 209 | @ "fossil_display_settings" cookie. |
| 184 | 210 | @ <ul> |
| 185 | 211 | @ <li>Raw cookie value: "%h(PD("fossil_display_settings",""))" |
| 186 | 212 | for(i=0; i<cookies.nParam; i++){ |
| 187 | 213 |
| --- src/cookies.c | |
| +++ src/cookies.c | |
| @@ -54,10 +54,15 @@ | |
| 54 | */ |
| 55 | #include "cookies.h" |
| 56 | #include <assert.h> |
| 57 | #include <string.h> |
| 58 | |
| 59 | |
| 60 | /* |
| 61 | ** State information private to this module |
| 62 | */ |
| 63 | #define COOKIE_NPARAM 10 |
| @@ -105,19 +110,25 @@ | |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | #define COOKIE_READ 1 |
| 109 | #define COOKIE_WRITE 2 |
| 110 | static void cookie_readwrite(const char *zQP, const char *zPName, int flags){ |
| 111 | const char *zQVal = P(zQP); |
| 112 | int i; |
| 113 | assert( cookies.zCookieName!=0 ); |
| 114 | for(i=0; i<cookies.nParam && strcmp(zPName,cookies.aParam[i].zPName); i++){} |
| 115 | if( (flags & COOKIE_READ)!=0 && zQVal==0 && i<cookies.nParam ){ |
| 116 | cgi_set_parameter_nocopy(zQP, cookies.aParam[i].zPValue, 1); |
| 117 | return; |
| 118 | } |
| 119 | if( (flags & COOKIE_WRITE)!=0 |
| 120 | && i<COOKIE_NPARAM |
| 121 | && (i==cookies.nParam || strcmp(zQVal, cookies.aParam[i].zPValue)) |
| 122 | ){ |
| 123 | if( i==cookies.nParam ){ |
| @@ -131,25 +142,33 @@ | |
| 131 | |
| 132 | /* If query parameter zQP is missing, initialize it using the zPName |
| 133 | ** value from the user preferences cookie |
| 134 | */ |
| 135 | void cookie_read_parameter(const char *zQP, const char *zPName){ |
| 136 | cookie_readwrite(zQP, zPName, COOKIE_READ); |
| 137 | } |
| 138 | |
| 139 | /* Update the zPName value of the user preference cookie to match |
| 140 | ** the value of query parameter zQP. |
| 141 | */ |
| 142 | void cookie_write_parameter(const char *zQP, const char *zPName){ |
| 143 | cookie_readwrite(zQP, zPName, COOKIE_WRITE); |
| 144 | } |
| 145 | |
| 146 | /* Use the zPName user preference value as a default for zQP and record |
| 147 | ** any changes to the zQP value back into the cookie. |
| 148 | */ |
| 149 | void cookie_link_parameter(const char *zQP, const char *zPName){ |
| 150 | cookie_readwrite(zQP, zPName, COOKIE_READ|COOKIE_WRITE); |
| 151 | } |
| 152 | |
| 153 | /* Update the user preferences cookie, if necessary, and shut down this |
| 154 | ** module |
| 155 | */ |
| @@ -175,12 +194,19 @@ | |
| 175 | ** Show the current display settings contained in the |
| 176 | ** "fossil_display_settings" cookie. |
| 177 | */ |
| 178 | void cookie_page(void){ |
| 179 | int i; |
| 180 | cookie_parse("fossil_display_settings"); |
| 181 | style_header("User Preference Cookie Values"); |
| 182 | @ <p>The following are user preference settings held in the |
| 183 | @ "fossil_display_settings" cookie. |
| 184 | @ <ul> |
| 185 | @ <li>Raw cookie value: "%h(PD("fossil_display_settings",""))" |
| 186 | for(i=0; i<cookies.nParam; i++){ |
| 187 |
| --- src/cookies.c | |
| +++ src/cookies.c | |
| @@ -54,10 +54,15 @@ | |
| 54 | */ |
| 55 | #include "cookies.h" |
| 56 | #include <assert.h> |
| 57 | #include <string.h> |
| 58 | |
| 59 | #if INTERFACE |
| 60 | /* the standard name of the display settings cookie for fossil */ |
| 61 | # define DISPLAY_SETTINGS_COOKIE "fossil_display_settings" |
| 62 | #endif |
| 63 | |
| 64 | |
| 65 | /* |
| 66 | ** State information private to this module |
| 67 | */ |
| 68 | #define COOKIE_NPARAM 10 |
| @@ -105,19 +110,25 @@ | |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | #define COOKIE_READ 1 |
| 114 | #define COOKIE_WRITE 2 |
| 115 | static void cookie_readwrite( |
| 116 | const char *zQP, /* Name of the query parameter */ |
| 117 | const char *zPName, /* Name of the cooking setting */ |
| 118 | const char *zDflt, /* Default value for the query parameter */ |
| 119 | int flags /* READ or WRITE or both */ |
| 120 | ){ |
| 121 | const char *zQVal = P(zQP); |
| 122 | int i; |
| 123 | assert( cookies.zCookieName!=0 ); |
| 124 | for(i=0; i<cookies.nParam && strcmp(zPName,cookies.aParam[i].zPName); i++){} |
| 125 | if( zQVal==0 && (flags & COOKIE_READ)!=0 && i<cookies.nParam ){ |
| 126 | cgi_set_parameter_nocopy(zQP, cookies.aParam[i].zPValue, 1); |
| 127 | return; |
| 128 | } |
| 129 | if( zQVal==0 ) zQVal = zDflt; |
| 130 | if( (flags & COOKIE_WRITE)!=0 |
| 131 | && i<COOKIE_NPARAM |
| 132 | && (i==cookies.nParam || strcmp(zQVal, cookies.aParam[i].zPValue)) |
| 133 | ){ |
| 134 | if( i==cookies.nParam ){ |
| @@ -131,25 +142,33 @@ | |
| 142 | |
| 143 | /* If query parameter zQP is missing, initialize it using the zPName |
| 144 | ** value from the user preferences cookie |
| 145 | */ |
| 146 | void cookie_read_parameter(const char *zQP, const char *zPName){ |
| 147 | cookie_readwrite(zQP, zPName, 0, COOKIE_READ); |
| 148 | } |
| 149 | |
| 150 | /* Update the zPName value of the user preference cookie to match |
| 151 | ** the value of query parameter zQP. |
| 152 | */ |
| 153 | void cookie_write_parameter( |
| 154 | const char *zQP, |
| 155 | const char *zPName, |
| 156 | const char *zDflt |
| 157 | ){ |
| 158 | cookie_readwrite(zQP, zPName, zDflt, COOKIE_WRITE); |
| 159 | } |
| 160 | |
| 161 | /* Use the zPName user preference value as a default for zQP and record |
| 162 | ** any changes to the zQP value back into the cookie. |
| 163 | */ |
| 164 | void cookie_link_parameter( |
| 165 | const char *zQP, /* The query parameter */ |
| 166 | const char *zPName, /* The name of the cookie value */ |
| 167 | const char *zDflt /* Default value for the parameter */ |
| 168 | ){ |
| 169 | cookie_readwrite(zQP, zPName, zDflt, COOKIE_READ|COOKIE_WRITE); |
| 170 | } |
| 171 | |
| 172 | /* Update the user preferences cookie, if necessary, and shut down this |
| 173 | ** module |
| 174 | */ |
| @@ -175,12 +194,19 @@ | |
| 194 | ** Show the current display settings contained in the |
| 195 | ** "fossil_display_settings" cookie. |
| 196 | */ |
| 197 | void cookie_page(void){ |
| 198 | int i; |
| 199 | if( PB("clear") ){ |
| 200 | cgi_set_cookie(DISPLAY_SETTINGS_COOKIE, "", 0, 1); |
| 201 | cgi_replace_parameter(DISPLAY_SETTINGS_COOKIE, ""); |
| 202 | } |
| 203 | cookie_parse(DISPLAY_SETTINGS_COOKIE); |
| 204 | style_header("User Preference Cookie Values"); |
| 205 | if( cookies.nParam ){ |
| 206 | style_submenu_element("Clear", "%R/cookies?clear"); |
| 207 | } |
| 208 | @ <p>The following are user preference settings held in the |
| 209 | @ "fossil_display_settings" cookie. |
| 210 | @ <ul> |
| 211 | @ <li>Raw cookie value: "%h(PD("fossil_display_settings",""))" |
| 212 | for(i=0; i<cookies.nParam; i++){ |
| 213 |
+5
-4
| --- src/timeline.c | ||
| +++ src/timeline.c | ||
| @@ -1647,12 +1647,12 @@ | ||
| 1647 | 1647 | "d", "Detailed", |
| 1648 | 1648 | "j", "Columnar", |
| 1649 | 1649 | }; |
| 1650 | 1650 | |
| 1651 | 1651 | /* Set number of rows to display */ |
| 1652 | - cookie_parse("fossil_display_settings"); | |
| 1653 | - cookie_link_parameter("n","n"); | |
| 1652 | + cookie_parse(DISPLAY_SETTINGS_COOKIE); | |
| 1653 | + cookie_read_parameter("n","n"); | |
| 1654 | 1654 | z = P("n"); |
| 1655 | 1655 | if( z==0 ) z = db_get("timeline-default-length",0); |
| 1656 | 1656 | if( z ){ |
| 1657 | 1657 | if( fossil_strcmp(z,"all")==0 ){ |
| 1658 | 1658 | nEntry = 0; |
| @@ -1665,11 +1665,12 @@ | ||
| 1665 | 1665 | } |
| 1666 | 1666 | }else{ |
| 1667 | 1667 | cgi_replace_query_parameter("n","50"); |
| 1668 | 1668 | nEntry = 50; |
| 1669 | 1669 | } |
| 1670 | - cookie_link_parameter("ss","ss"); | |
| 1670 | + cookie_write_parameter("n","n",0); | |
| 1671 | + cookie_link_parameter("ss","ss","n"); | |
| 1671 | 1672 | cViewStyle = PD("ss","n")[0]; |
| 1672 | 1673 | style_submenu_multichoice("ss", 4, azViewStyles, 0); |
| 1673 | 1674 | |
| 1674 | 1675 | |
| 1675 | 1676 | /* To view the timeline, must have permission to read project data. |
| @@ -1690,11 +1691,11 @@ | ||
| 1690 | 1691 | if( zType==0 ){ |
| 1691 | 1692 | zType = g.perm.Read ? "ci" : "all"; |
| 1692 | 1693 | cgi_set_parameter("y", zType); |
| 1693 | 1694 | } |
| 1694 | 1695 | if( zType[0]=='a' || zType[0]=='c' ){ |
| 1695 | - cookie_write_parameter("y","y"); | |
| 1696 | + cookie_write_parameter("y","y",zType); | |
| 1696 | 1697 | } |
| 1697 | 1698 | cookie_render(); |
| 1698 | 1699 | url_initialize(&url, "timeline"); |
| 1699 | 1700 | cgi_query_parameters_to_url(&url); |
| 1700 | 1701 | |
| 1701 | 1702 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -1647,12 +1647,12 @@ | |
| 1647 | "d", "Detailed", |
| 1648 | "j", "Columnar", |
| 1649 | }; |
| 1650 | |
| 1651 | /* Set number of rows to display */ |
| 1652 | cookie_parse("fossil_display_settings"); |
| 1653 | cookie_link_parameter("n","n"); |
| 1654 | z = P("n"); |
| 1655 | if( z==0 ) z = db_get("timeline-default-length",0); |
| 1656 | if( z ){ |
| 1657 | if( fossil_strcmp(z,"all")==0 ){ |
| 1658 | nEntry = 0; |
| @@ -1665,11 +1665,12 @@ | |
| 1665 | } |
| 1666 | }else{ |
| 1667 | cgi_replace_query_parameter("n","50"); |
| 1668 | nEntry = 50; |
| 1669 | } |
| 1670 | cookie_link_parameter("ss","ss"); |
| 1671 | cViewStyle = PD("ss","n")[0]; |
| 1672 | style_submenu_multichoice("ss", 4, azViewStyles, 0); |
| 1673 | |
| 1674 | |
| 1675 | /* To view the timeline, must have permission to read project data. |
| @@ -1690,11 +1691,11 @@ | |
| 1690 | if( zType==0 ){ |
| 1691 | zType = g.perm.Read ? "ci" : "all"; |
| 1692 | cgi_set_parameter("y", zType); |
| 1693 | } |
| 1694 | if( zType[0]=='a' || zType[0]=='c' ){ |
| 1695 | cookie_write_parameter("y","y"); |
| 1696 | } |
| 1697 | cookie_render(); |
| 1698 | url_initialize(&url, "timeline"); |
| 1699 | cgi_query_parameters_to_url(&url); |
| 1700 | |
| 1701 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -1647,12 +1647,12 @@ | |
| 1647 | "d", "Detailed", |
| 1648 | "j", "Columnar", |
| 1649 | }; |
| 1650 | |
| 1651 | /* Set number of rows to display */ |
| 1652 | cookie_parse(DISPLAY_SETTINGS_COOKIE); |
| 1653 | cookie_read_parameter("n","n"); |
| 1654 | z = P("n"); |
| 1655 | if( z==0 ) z = db_get("timeline-default-length",0); |
| 1656 | if( z ){ |
| 1657 | if( fossil_strcmp(z,"all")==0 ){ |
| 1658 | nEntry = 0; |
| @@ -1665,11 +1665,12 @@ | |
| 1665 | } |
| 1666 | }else{ |
| 1667 | cgi_replace_query_parameter("n","50"); |
| 1668 | nEntry = 50; |
| 1669 | } |
| 1670 | cookie_write_parameter("n","n",0); |
| 1671 | cookie_link_parameter("ss","ss","n"); |
| 1672 | cViewStyle = PD("ss","n")[0]; |
| 1673 | style_submenu_multichoice("ss", 4, azViewStyles, 0); |
| 1674 | |
| 1675 | |
| 1676 | /* To view the timeline, must have permission to read project data. |
| @@ -1690,11 +1691,11 @@ | |
| 1691 | if( zType==0 ){ |
| 1692 | zType = g.perm.Read ? "ci" : "all"; |
| 1693 | cgi_set_parameter("y", zType); |
| 1694 | } |
| 1695 | if( zType[0]=='a' || zType[0]=='c' ){ |
| 1696 | cookie_write_parameter("y","y",zType); |
| 1697 | } |
| 1698 | cookie_render(); |
| 1699 | url_initialize(&url, "timeline"); |
| 1700 | cgi_query_parameters_to_url(&url); |
| 1701 | |
| 1702 |