Fossil SCM

Improvements to handling of the cookie for "sticky" display settings.

drh 2017-11-28 22:16 UTC sticky-timeline-style
Commit 3ec843970d10dc705150b76e9c2db4f8044504467c2d4317d71b492c4fd2d825
2 files changed +34 -8 +5 -4
+34 -8
--- src/cookies.c
+++ src/cookies.c
@@ -54,10 +54,15 @@
5454
*/
5555
#include "cookies.h"
5656
#include <assert.h>
5757
#include <string.h>
5858
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
+
5964
6065
/*
6166
** State information private to this module
6267
*/
6368
#define COOKIE_NPARAM 10
@@ -105,19 +110,25 @@
105110
}
106111
}
107112
108113
#define COOKIE_READ 1
109114
#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
+){
111121
const char *zQVal = P(zQP);
112122
int i;
113123
assert( cookies.zCookieName!=0 );
114124
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 ){
116126
cgi_set_parameter_nocopy(zQP, cookies.aParam[i].zPValue, 1);
117127
return;
118128
}
129
+ if( zQVal==0 ) zQVal = zDflt;
119130
if( (flags & COOKIE_WRITE)!=0
120131
&& i<COOKIE_NPARAM
121132
&& (i==cookies.nParam || strcmp(zQVal, cookies.aParam[i].zPValue))
122133
){
123134
if( i==cookies.nParam ){
@@ -131,25 +142,33 @@
131142
132143
/* If query parameter zQP is missing, initialize it using the zPName
133144
** value from the user preferences cookie
134145
*/
135146
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);
137148
}
138149
139150
/* Update the zPName value of the user preference cookie to match
140151
** the value of query parameter zQP.
141152
*/
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);
144159
}
145160
146161
/* Use the zPName user preference value as a default for zQP and record
147162
** any changes to the zQP value back into the cookie.
148163
*/
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);
151170
}
152171
153172
/* Update the user preferences cookie, if necessary, and shut down this
154173
** module
155174
*/
@@ -175,12 +194,19 @@
175194
** Show the current display settings contained in the
176195
** "fossil_display_settings" cookie.
177196
*/
178197
void cookie_page(void){
179198
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);
181204
style_header("User Preference Cookie Values");
205
+ if( cookies.nParam ){
206
+ style_submenu_element("Clear", "%R/cookies?clear");
207
+ }
182208
@ <p>The following are user preference settings held in the
183209
@ "fossil_display_settings" cookie.
184210
@ <ul>
185211
@ <li>Raw cookie value: "%h(PD("fossil_display_settings",""))"
186212
for(i=0; i<cookies.nParam; i++){
187213
--- 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 @@
16471647
"d", "Detailed",
16481648
"j", "Columnar",
16491649
};
16501650
16511651
/* 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");
16541654
z = P("n");
16551655
if( z==0 ) z = db_get("timeline-default-length",0);
16561656
if( z ){
16571657
if( fossil_strcmp(z,"all")==0 ){
16581658
nEntry = 0;
@@ -1665,11 +1665,12 @@
16651665
}
16661666
}else{
16671667
cgi_replace_query_parameter("n","50");
16681668
nEntry = 50;
16691669
}
1670
- cookie_link_parameter("ss","ss");
1670
+ cookie_write_parameter("n","n",0);
1671
+ cookie_link_parameter("ss","ss","n");
16711672
cViewStyle = PD("ss","n")[0];
16721673
style_submenu_multichoice("ss", 4, azViewStyles, 0);
16731674
16741675
16751676
/* To view the timeline, must have permission to read project data.
@@ -1690,11 +1691,11 @@
16901691
if( zType==0 ){
16911692
zType = g.perm.Read ? "ci" : "all";
16921693
cgi_set_parameter("y", zType);
16931694
}
16941695
if( zType[0]=='a' || zType[0]=='c' ){
1695
- cookie_write_parameter("y","y");
1696
+ cookie_write_parameter("y","y",zType);
16961697
}
16971698
cookie_render();
16981699
url_initialize(&url, "timeline");
16991700
cgi_query_parameters_to_url(&url);
17001701
17011702
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button