Browse Source

[page] ajout du champs "pad_url" dans l'édition des pages

Maxime Alves LIRMM@home 3 years ago
parent
commit
7a8401fd6a
3 changed files with 37 additions and 20 deletions
  1. 28
    17
      src/page.cpp
  2. 5
    3
      src/page_content.h
  3. 4
    0
      templates/page.tmpl

+ 28
- 17
src/page.cpp View File

16
 {
16
 {
17
 	title.message(_("Title"));
17
 	title.message(_("Title"));
18
 	content.message(_("Content"));
18
 	content.message(_("Content"));
19
+	pad_url.message(_("Pad URL"));
19
 	sidebar.message(_("Sidebar"));
20
 	sidebar.message(_("Sidebar"));
20
 	save.value(_("Save"));
21
 	save.value(_("Save"));
21
 	save_cont.value(_("Save and Continue"));
22
 	save_cont.value(_("Save and Continue"));
22
 	preview.value(_("Preview"));
23
 	preview.value(_("Preview"));
23
 	fields.add(title);
24
 	fields.add(title);
24
 	fields.add(content);
25
 	fields.add(content);
26
+	fields.add(pad_url);
25
 	fields.add(sidebar);
27
 	fields.add(sidebar);
26
 	buttons.add(save);
28
 	buttons.add(save);
27
 	buttons.add(save_cont);
29
 	buttons.add(save_cont);
32
 	users_only.help(_("Disable editing by visitors"));
34
 	users_only.help(_("Disable editing by visitors"));
33
 	users_only.error_message(_("Please Login"));
35
 	users_only.error_message(_("Please Login"));
34
 	title.non_empty();
36
 	title.non_empty();
35
-	content.non_empty();
36
 	content.rows(25);
37
 	content.rows(25);
37
 	content.cols(60);
38
 	content.cols(60);
38
 	sidebar.rows(10);
39
 	sidebar.rows(10);
113
 	c.v2=v2;
114
 	c.v2=v2;
114
 	c.edit_v1=edit_version_url(v1);
115
 	c.edit_v1=edit_version_url(v1);
115
 	c.edit_v2=edit_version_url(v2);
116
 	c.edit_v2=edit_version_url(v2);
116
-	r=sql<<	"SELECT version,history.title,history.content,history.sidebar,pages.title FROM pages "
117
+	r=sql<<	"SELECT version,history.title,history.content,history.pad_url,history.sidebar,pages.title FROM pages "
117
 		"JOIN history ON pages.id=history.id "
118
 		"JOIN history ON pages.id=history.id "
118
 		"WHERE lang=? AND slug=? AND version IN (?,?) " << locale_name << slug << v1 << v2;
119
 		"WHERE lang=? AND slug=? AND version IN (?,?) " << locale_name << slug << v1 << v2;
119
 	
120
 	
120
-	std::string t1,c1,s1,t2,c2,s2;
121
+	std::string t1,c1,p1,s1,t2,c2,p2,s2;
121
 	int count=0;
122
 	int count=0;
122
 	while(r.next()) {
123
 	while(r.next()) {
123
 		int ver;
124
 		int ver;
124
 		r>>ver;
125
 		r>>ver;
125
 		if(ver==v1) {
126
 		if(ver==v1) {
126
-			r>>t1>>c1>>s1>>c.title;
127
+			r>>t1>>c1>>p2>>s1>>c.title;
127
 		}
128
 		}
128
 		else {
129
 		else {
129
-			r>>t2>>c2>>s2;
130
+			r>>t2>>c2>>p2>>s2;
130
 		}
131
 		}
131
 		count++;
132
 		count++;
132
 	}
133
 	}
150
 		std::vector<std::string> Y=split(c2);
151
 		std::vector<std::string> Y=split(c2);
151
 		diff::diff(X,Y,c.content_diff_content);
152
 		diff::diff(X,Y,c.content_diff_content);
152
 	}
153
 	}
154
+	if(p1!=p2) {
155
+		c.pad_url_diff=true;
156
+		std::vector<std::string> X=split(p1);
157
+		std::vector<std::string> Y=split(p2);
158
+		diff::diff(X,Y,c.pad_url_diff_content);
159
+	}
153
 	if(s1!=s2) {
160
 	if(s1!=s2) {
154
 		c.sidebar_diff=true;
161
 		c.sidebar_diff=true;
155
 		std::vector<std::string> X=split(s1);
162
 		std::vector<std::string> X=split(s1);
156
 		std::vector<std::string> Y=split(s2);
163
 		std::vector<std::string> Y=split(s2);
157
 		diff::diff(X,Y,c.sidebar_diff_content);
164
 		diff::diff(X,Y,c.sidebar_diff_content);
158
 	}
165
 	}
159
-	if(t1==t2 && c1==c2 && s1==s2) 
166
+	if(t1==t2 && c1==c2 && p1==p2 && s1==s2)
160
 		c.no_diff=true;
167
 		c.no_diff=true;
161
 	master::ini(c);
168
 	master::ini(c);
162
 	render("diff",c);
169
 	render("diff",c);
282
 {
289
 {
283
 	cppdb::session sql(conn);
290
 	cppdb::session sql(conn);
284
 	cppdb::result r;
291
 	cppdb::result r;
285
-	r=sql<<	"SELECT title,content,sidebar,users_only "
292
+	r=sql<<	"SELECT title,content,pad_url,sidebar,users_only "
286
 		"FROM pages WHERE lang=? AND slug=?" << locale_name << slug << cppdb::row;
293
 		"FROM pages WHERE lang=? AND slug=?" << locale_name << slug << cppdb::row;
287
 	if(!r.empty()) {
294
 	if(!r.empty()) {
288
 		std::string title,content,sidebar;
295
 		std::string title,content,sidebar;
310
 	std::tm t = booster::ptime::local_time(booster::ptime::now());
317
 	std::tm t = booster::ptime::local_time(booster::ptime::now());
311
 	wi.users.auth();
318
 	wi.users.auth();
312
 	if(id!=-1) {
319
 	if(id!=-1) {
313
-		sql<<	"UPDATE pages SET content=?,title=?,sidebar=?,users_only=? "
320
+		sql<<	"UPDATE pages SET content=?,title=?,pad_url=?,sidebar=?,users_only=? "
314
 			"WHERE lang=? AND slug=?"
321
 			"WHERE lang=? AND slug=?"
315
-				<< form.content.value() << form.title.value() 
322
+				<< form.content.value() << form.title.value() << form.pad_url.value()
316
 				<< form.sidebar.value() << form.users_only.value() 
323
 				<< form.sidebar.value() << form.users_only.value() 
317
 				<< locale_name << slug << cppdb::exec;
324
 				<< locale_name << slug << cppdb::exec;
318
 	}
325
 	}
319
 	else {
326
 	else {
320
 		cppdb::statement s;
327
 		cppdb::statement s;
321
-		s=sql<<	"INSERT INTO pages(lang,slug,title,content,sidebar,users_only) "
322
-			"VALUES(?,?,?,?,?,?)"
328
+		s=sql<<	"INSERT INTO pages(lang,slug,title,content,pad_url,sidebar,users_only) "
329
+			"VALUES(?,?,?,?,?,?,?)"
323
 			<< locale_name << slug
330
 			<< locale_name << slug
324
 			<< form.title.value()
331
 			<< form.title.value()
325
 			<< form.content.value()
332
 			<< form.content.value()
333
+			<< form.pad_url.value()
326
 			<< form.sidebar.value()
334
 			<< form.sidebar.value()
327
 			<< form.users_only.value();
335
 			<< form.users_only.value();
328
 		s.exec();
336
 		s.exec();
329
 		id=s.sequence_last("pages_id_seq");
337
 		id=s.sequence_last("pages_id_seq");
330
 	}
338
 	}
331
-	sql<<	"INSERT INTO history(id,version,created,title,content,sidebar,author) "
339
+	sql<<	"INSERT INTO history(id,version,created,title,content,pad_url,sidebar,author) "
332
 		"SELECT ?,"
340
 		"SELECT ?,"
333
 		"	(SELECT COALESCE(MAX(version),0)+1 FROM history WHERE id=?),"
341
 		"	(SELECT COALESCE(MAX(version),0)+1 FROM history WHERE id=?),"
334
-		"	?,?,?,?,?"
342
+		"	?,?,?,?,?,?"
335
 			<< id << id << t 
343
 			<< id << id << t 
336
 			<< form.title.value()
344
 			<< form.title.value()
337
 			<< form.content.value()
345
 			<< form.content.value()
346
+			<< form.pad_url.value()
338
 			<< form.sidebar.value()
347
 			<< form.sidebar.value()
339
 			<< wi.users.username 
348
 			<< wi.users.username 
340
 			<< cppdb::exec;
349
 			<< cppdb::exec;
373
 		if(c.form.preview.value()) {
382
 		if(c.form.preview.value()) {
374
 			c.title=c.form.title.value();
383
 			c.title=c.form.title.value();
375
 			c.content=c.form.content.value();
384
 			c.content=c.form.content.value();
385
+			c.pad_url=c.form.pad_url.value();
376
 			c.sidebar=c.form.sidebar.value();
386
 			c.sidebar=c.form.sidebar.value();
377
 		}
387
 		}
378
 	}
388
 	}
384
 {
394
 {
385
 	cppdb::session sql(conn);
395
 	cppdb::session sql(conn);
386
 	cppdb::result r;
396
 	cppdb::result r;
387
-	r=sql<<	"SELECT history.title,history.content,history.sidebar,pages.users_only "
397
+	r=sql<<	"SELECT history.title,history.content,history.pad_url,history.sidebar,pages.users_only "
388
 		"FROM pages "
398
 		"FROM pages "
389
 		"JOIN history ON pages.id=history.id "
399
 		"JOIN history ON pages.id=history.id "
390
 		"WHERE pages.lang=? AND pages.slug=? AND history.version=?"
400
 		"WHERE pages.lang=? AND pages.slug=? AND history.version=?"
391
 		<<locale_name<<slug<<ver<<cppdb::row;
401
 		<<locale_name<<slug<<ver<<cppdb::row;
392
 	if(!r.empty()) {
402
 	if(!r.empty()) {
393
-		std::string title,content,sidebar;
403
+		std::string title,content,pad_url,sidebar;
394
 		int uonly;
404
 		int uonly;
395
-		r >> title >> content >> sidebar >> uonly;
405
+		r >> title >> content >> pad_url >> sidebar >> uonly;
396
 		form.title.value(title);
406
 		form.title.value(title);
397
 		form.content.value(content);
407
 		form.content.value(content);
408
+		form.pad_url.value(pad_url);
398
 		form.sidebar.value(sidebar);
409
 		form.sidebar.value(sidebar);
399
 		form.users_only.value(uonly);
410
 		form.users_only.value(uonly);
400
 		return true;
411
 		return true;
409
 	int id=atoi(sid.c_str());
420
 	int id=atoi(sid.c_str());
410
 	cppdb::result r;
421
 	cppdb::result r;
411
 	cppdb::session sql(conn);
422
 	cppdb::session sql(conn);
412
-	r=sql<<	"SELECT history.title,history.content,history.sidebar,history.created "
423
+	r=sql<<	"SELECT history.title,history.content,history.pad_url,history.sidebar,history.created "
413
 		"FROM pages "
424
 		"FROM pages "
414
 		"JOIN history ON pages.id=history.id "
425
 		"JOIN history ON pages.id=history.id "
415
 		"WHERE pages.lang=? AND pages.slug=? AND history.version=?"
426
 		"WHERE pages.lang=? AND pages.slug=? AND history.version=?"

+ 5
- 3
src/page_content.h View File

11
 	apps::wiki *w;
11
 	apps::wiki *w;
12
 	cppcms::widgets::text title;
12
 	cppcms::widgets::text title;
13
 	cppcms::widgets::textarea content;
13
 	cppcms::widgets::textarea content;
14
+	cppcms::widgets::text pad_url;
14
 	cppcms::widgets::textarea sidebar;
15
 	cppcms::widgets::textarea sidebar;
15
 	cppcms::widgets::submit save;
16
 	cppcms::widgets::submit save;
16
 	cppcms::widgets::submit save_cont;
17
 	cppcms::widgets::submit save_cont;
24
 
25
 
25
 struct page : public master {
26
 struct page : public master {
26
 	std::string title,content;
27
 	std::string title,content;
27
-	std::string sidebar;
28
+	std::string pad_url,sidebar;
28
 	std::string edit_link;
29
 	std::string edit_link;
29
 	std::string history_link;
30
 	std::string history_link;
30
 };
31
 };
62
 	std::string edit_v1,edit_v2;
63
 	std::string edit_v1,edit_v2;
63
 	int v1,v2;
64
 	int v1,v2;
64
 	diff_t content_diff_content;
65
 	diff_t content_diff_content;
66
+	diff_t pad_url_diff_content;
65
 	diff_t sidebar_diff_content;
67
 	diff_t sidebar_diff_content;
66
 	std::string title,title_1,title_2;
68
 	std::string title,title_1,title_2;
67
-	bool title_diff,content_diff,sidebar_diff,no_versions,no_diff;
69
+	bool title_diff,content_diff,pad_url_diff,sidebar_diff,no_versions,no_diff;
68
 	diff() : 
70
 	diff() : 
69
-		title_diff(false),content_diff(false),
71
+		title_diff(false),content_diff(false),pad_url_diff(false),
70
 		sidebar_diff(false),no_versions(false),
72
 		sidebar_diff(false),no_versions(false),
71
 		no_diff(false)
73
 		no_diff(false)
72
 	{
74
 	{

+ 4
- 0
templates/page.tmpl View File

111
 		<h2><% gt "Content" %>:</h2>
111
 		<h2><% gt "Content" %>:</h2>
112
 		<% include show_diff(content_diff_content) %>
112
 		<% include show_diff(content_diff_content) %>
113
 	<% end %>
113
 	<% end %>
114
+	<% if pad_url_diff %>
115
+		<h2><% gt "Pad URL" %>:</h2>
116
+		<% include show_diff(pad_url_diff_content) %>
117
+	<% end %>
114
 	<% if sidebar_diff %>
118
 	<% if sidebar_diff %>
115
 		<h2><% gt "Sidebar" %>:</h2>
119
 		<h2><% gt "Sidebar" %>:</h2>
116
 		<% include show_diff(sidebar_diff_content) %>
120
 		<% include show_diff(sidebar_diff_content) %>

Loading…
Cancel
Save