Fossil SCM

Test commands for importing and exporting ticket configurations.

drh 2007-10-03 12:20 trunk
Commit 1e9c0e287e9609f3ee097136ff751d4701278cf5
+3 -3
--- src/db.c
+++ src/db.c
@@ -832,12 +832,12 @@
832832
833833
/*
834834
** Get and set values from the CONFIG, GLOBAL_CONFIG and VVAR table in the
835835
** repository and local databases.
836836
*/
837
-const char *db_get(const char *zName, const char *zDefault){
838
- const char *z = 0;
837
+char *db_get(const char *zName, char *zDefault){
838
+ char *z = 0;
839839
if( g.repositoryOpen ){
840840
z = db_text(0, "SELECT value FROM config WHERE name=%Q", zName);
841841
}
842842
if( z==0 ){
843843
z = db_text(0, "SELECT value FROM global_config WHERE name=%Q", zName);
@@ -885,11 +885,11 @@
885885
if( globalFlag && g.repositoryOpen ){
886886
db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
887887
}
888888
db_end_transaction(0);
889889
}
890
-char *db_lget(const char *zName, const char *zDefault){
890
+char *db_lget(const char *zName, char *zDefault){
891891
return db_text((char*)zDefault,
892892
"SELECT value FROM vvar WHERE name=%Q", zName);
893893
}
894894
void db_lset(const char *zName, const char *zValue){
895895
db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%Q)", zName, zValue);
896896
--- src/db.c
+++ src/db.c
@@ -832,12 +832,12 @@
832
833 /*
834 ** Get and set values from the CONFIG, GLOBAL_CONFIG and VVAR table in the
835 ** repository and local databases.
836 */
837 const char *db_get(const char *zName, const char *zDefault){
838 const char *z = 0;
839 if( g.repositoryOpen ){
840 z = db_text(0, "SELECT value FROM config WHERE name=%Q", zName);
841 }
842 if( z==0 ){
843 z = db_text(0, "SELECT value FROM global_config WHERE name=%Q", zName);
@@ -885,11 +885,11 @@
885 if( globalFlag && g.repositoryOpen ){
886 db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
887 }
888 db_end_transaction(0);
889 }
890 char *db_lget(const char *zName, const char *zDefault){
891 return db_text((char*)zDefault,
892 "SELECT value FROM vvar WHERE name=%Q", zName);
893 }
894 void db_lset(const char *zName, const char *zValue){
895 db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%Q)", zName, zValue);
896
--- src/db.c
+++ src/db.c
@@ -832,12 +832,12 @@
832
833 /*
834 ** Get and set values from the CONFIG, GLOBAL_CONFIG and VVAR table in the
835 ** repository and local databases.
836 */
837 char *db_get(const char *zName, char *zDefault){
838 char *z = 0;
839 if( g.repositoryOpen ){
840 z = db_text(0, "SELECT value FROM config WHERE name=%Q", zName);
841 }
842 if( z==0 ){
843 z = db_text(0, "SELECT value FROM global_config WHERE name=%Q", zName);
@@ -885,11 +885,11 @@
885 if( globalFlag && g.repositoryOpen ){
886 db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
887 }
888 db_end_transaction(0);
889 }
890 char *db_lget(const char *zName, char *zDefault){
891 return db_text((char*)zDefault,
892 "SELECT value FROM vvar WHERE name=%Q", zName);
893 }
894 void db_lset(const char *zName, const char *zValue){
895 db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%Q)", zName, zValue);
896
+9
--- src/main.c
+++ src/main.c
@@ -596,10 +596,19 @@
596596
db_must_be_within_tree();
597597
}
598598
cgi_handle_http_request();
599599
process_one_web_page();
600600
}
601
+
602
+/*
603
+** COMMAND: test-http
604
+** Works like the http command but gives setup permission to all users.
605
+*/
606
+void cmd_test_http(void){
607
+ login_set_capabilities("s");
608
+ cmd_http();
609
+}
601610
602611
/*
603612
** COMMAND: server
604613
**
605614
** Usage: %fossil server ?-P|--port TCPPORT? ?REPOSITORY?
606615
--- src/main.c
+++ src/main.c
@@ -596,10 +596,19 @@
596 db_must_be_within_tree();
597 }
598 cgi_handle_http_request();
599 process_one_web_page();
600 }
 
 
 
 
 
 
 
 
 
601
602 /*
603 ** COMMAND: server
604 **
605 ** Usage: %fossil server ?-P|--port TCPPORT? ?REPOSITORY?
606
--- src/main.c
+++ src/main.c
@@ -596,10 +596,19 @@
596 db_must_be_within_tree();
597 }
598 cgi_handle_http_request();
599 process_one_web_page();
600 }
601
602 /*
603 ** COMMAND: test-http
604 ** Works like the http command but gives setup permission to all users.
605 */
606 void cmd_test_http(void){
607 login_set_capabilities("s");
608 cmd_http();
609 }
610
611 /*
612 ** COMMAND: server
613 **
614 ** Usage: %fossil server ?-P|--port TCPPORT? ?REPOSITORY?
615
+2 -2
--- src/setup.c
+++ src/setup.c
@@ -450,11 +450,11 @@
450450
static void entry_attribute(
451451
const char *zLabel, /* The text label on the entry box */
452452
int width, /* Width of the entry box */
453453
const char *zVar, /* The corresponding row in the VAR table */
454454
const char *zQParm, /* The query parameter */
455
- const char *zDflt /* Default value if VAR table entry does not exist */
455
+ char *zDflt /* Default value if VAR table entry does not exist */
456456
){
457457
const char *zVal = db_get(zVar, zDflt);
458458
const char *zQ = P(zQParm);
459459
if( zQ && strcmp(zQ,zVal)!=0 ){
460460
db_set(zVar, zQ, 0);
@@ -471,11 +471,11 @@
471471
const char *zLabel, /* The text label on the textarea */
472472
int rows, /* Rows in the textarea */
473473
int cols, /* Columns in the textarea */
474474
const char *zVar, /* The corresponding row in the VAR table */
475475
const char *zQParm, /* The query parameter */
476
- const char *zDflt /* Default value if VAR table entry does not exist */
476
+ char *zDflt /* Default value if VAR table entry does not exist */
477477
){
478478
const char *zVal = db_get(zVar, zDflt);
479479
const char *zQ = P(zQParm);
480480
if( zQ && strcmp(zQ,zVal)!=0 ){
481481
db_set(zVar, zQ, 0);
482482
--- src/setup.c
+++ src/setup.c
@@ -450,11 +450,11 @@
450 static void entry_attribute(
451 const char *zLabel, /* The text label on the entry box */
452 int width, /* Width of the entry box */
453 const char *zVar, /* The corresponding row in the VAR table */
454 const char *zQParm, /* The query parameter */
455 const char *zDflt /* Default value if VAR table entry does not exist */
456 ){
457 const char *zVal = db_get(zVar, zDflt);
458 const char *zQ = P(zQParm);
459 if( zQ && strcmp(zQ,zVal)!=0 ){
460 db_set(zVar, zQ, 0);
@@ -471,11 +471,11 @@
471 const char *zLabel, /* The text label on the textarea */
472 int rows, /* Rows in the textarea */
473 int cols, /* Columns in the textarea */
474 const char *zVar, /* The corresponding row in the VAR table */
475 const char *zQParm, /* The query parameter */
476 const char *zDflt /* Default value if VAR table entry does not exist */
477 ){
478 const char *zVal = db_get(zVar, zDflt);
479 const char *zQ = P(zQParm);
480 if( zQ && strcmp(zQ,zVal)!=0 ){
481 db_set(zVar, zQ, 0);
482
--- src/setup.c
+++ src/setup.c
@@ -450,11 +450,11 @@
450 static void entry_attribute(
451 const char *zLabel, /* The text label on the entry box */
452 int width, /* Width of the entry box */
453 const char *zVar, /* The corresponding row in the VAR table */
454 const char *zQParm, /* The query parameter */
455 char *zDflt /* Default value if VAR table entry does not exist */
456 ){
457 const char *zVal = db_get(zVar, zDflt);
458 const char *zQ = P(zQParm);
459 if( zQ && strcmp(zQ,zVal)!=0 ){
460 db_set(zVar, zQ, 0);
@@ -471,11 +471,11 @@
471 const char *zLabel, /* The text label on the textarea */
472 int rows, /* Rows in the textarea */
473 int cols, /* Columns in the textarea */
474 const char *zVar, /* The corresponding row in the VAR table */
475 const char *zQParm, /* The query parameter */
476 char *zDflt /* Default value if VAR table entry does not exist */
477 ){
478 const char *zVal = db_get(zVar, zDflt);
479 const char *zQ = P(zQParm);
480 if( zQ && strcmp(zQ,zVal)!=0 ){
481 db_set(zVar, zQ, 0);
482
+107 -4
--- src/tktconf.c
+++ src/tktconf.c
@@ -152,19 +152,19 @@
152152
** the tktfield table and to insert template text into the
153153
** config table
154154
*/
155155
blob_appendf(&tbldef,
156156
"DROP TABLE IF EXISTS ticket;\n"
157
- "CREATE TABLE ticket(\n"
157
+ "CREATE TABLE repository.ticket(\n"
158158
" tktid INTEGER PRIMARY KEY,\n"
159159
" tktuuid TEXT UNIQUE,\n"
160160
" starttime DATETIME,\n"
161161
" lastmod DATETIME"
162162
);
163163
blob_appendf(&sql,
164164
"DROP TABLE IF EXISTS tktfield;\n"
165
- "CREATE TABLE tktfield(\n"
165
+ "CREATE TABLE repository.tktfield(\n"
166166
" fidx INTEGER PRIMARY KEY,\n"
167167
" name TEXT UNIQUE,\n"
168168
" type TEXT,\n"
169169
" width INTEGER,\n"
170170
" arg\n"
@@ -308,11 +308,10 @@
308308
** <text>
309309
*/
310310
if( blob_eq(&token, "description")
311311
&& blob_token(&line, &arg)
312312
){
313
- int idx;
314313
Blob content;
315314
int start;
316315
int end;
317316
318317
start = end = blob_tell(pConfig);
@@ -367,18 +366,36 @@
367366
}
368367
369368
/*
370369
** COMMAND: test-tktconfig-parse
371370
*/
372
-void test_tktconfig_cmd(void){
371
+void test_tktconfig_parse_cmd(void){
373372
Blob config, err;
374373
if( g.argc!=3 ){
375374
usage("FILENAME");
376375
}
377376
blob_read_from_file(&config, g.argv[2]);
378377
blob_zero(&err);
379378
ticket_config_parse(&config, 1, &err);
379
+ if( blob_size(&err) ){
380
+ blob_write_to_file(&err, "-");
381
+ }
382
+}
383
+/*
384
+** COMMAND: test-tktconfig-import
385
+*/
386
+void test_tktconfig_import_cmd(void){
387
+ Blob config, err;
388
+ db_must_be_within_tree();
389
+ if( g.argc!=3 ){
390
+ usage("FILENAME");
391
+ }
392
+ blob_read_from_file(&config, g.argv[2]);
393
+ blob_zero(&err);
394
+ db_begin_transaction();
395
+ ticket_config_parse(&config, 0, &err);
396
+ db_end_transaction(0);
380397
if( blob_size(&err) ){
381398
blob_write_to_file(&err, "-");
382399
}
383400
}
384401
@@ -561,5 +578,91 @@
561578
if( blob_size(&errmsg) ){
562579
fossil_fatal("%b", &errmsg);
563580
}
564581
db_end_transaction(0);
565582
}
583
+
584
+/*
585
+** Return the length of a string without its trailing whitespace.
586
+*/
587
+static int non_whitespace_length(const char *z){
588
+ int n = strlen(z);
589
+ while( n>0 && isspace(z[n-1]) ){ n--; }
590
+ return n;
591
+}
592
+
593
+/*
594
+** Fill the given Blob with text that describes the current
595
+** ticket configuration. This is the inverse of ticket_config_parse()
596
+*/
597
+void ticket_config_render(Blob *pOut){
598
+ char *zDelim;
599
+ char *zContent;
600
+ Stmt q;
601
+ int n;
602
+
603
+ blob_appendf(pOut, "ticket-configuration\n");
604
+ zDelim = db_text(0, "SELECT '--end-of-text--' || hex(random(20))");
605
+ blob_appendf(pOut, "###################################################\n");
606
+ db_prepare(&q, "SELECT name, type, width, arg FROM tktfield");
607
+ while( db_step(&q)==SQLITE_ROW ){
608
+ const char *zName = db_column_text(&q, 0);
609
+ const char *zType = db_column_text(&q, 1);
610
+ int width = db_column_int(&q, 2);
611
+ const char *zArg = db_column_text(&q, 3);
612
+ blob_appendf(pOut, "field %s %s %d %s\n", zName, zType, width, zArg);
613
+ }
614
+ db_finalize(&q);
615
+ blob_appendf(pOut, "###################################################\n");
616
+ blob_appendf(pOut, "template new %s\n", zDelim);
617
+ zContent = db_get("tkt-new-template", 0);
618
+ if( zContent ){
619
+ n = non_whitespace_length(zContent);
620
+ blob_appendf(pOut, "%.*s\n", n, zContent);
621
+ free(zContent);
622
+ }
623
+ blob_appendf(pOut, "%s\n", zDelim);
624
+ blob_appendf(pOut, "###################################################\n");
625
+ blob_appendf(pOut, "template edit %s\n", zDelim);
626
+ zContent = db_get("tkt-edit-template", 0);
627
+ if( zContent ){
628
+ n = non_whitespace_length(zContent);
629
+ blob_appendf(pOut, "%.*s\n", n, zContent);
630
+ free(zContent);
631
+ }
632
+ blob_appendf(pOut, "%s\n", zDelim);
633
+ blob_appendf(pOut, "###################################################\n");
634
+ blob_appendf(pOut, "template view %s\n", zDelim);
635
+ zContent = db_get("tkt-view-template", 0);
636
+ if( zContent ){
637
+ n = non_whitespace_length(zContent);
638
+ blob_appendf(pOut, "%.*s\n", n, zContent);
639
+ free(zContent);
640
+ }
641
+ blob_appendf(pOut, "%s\n", zDelim);
642
+ blob_appendf(pOut, "###################################################\n");
643
+ blob_appendf(pOut, "description %s\n", zDelim);
644
+ zContent = db_get("tkt-desc", 0);
645
+ if( zContent ){
646
+ n = non_whitespace_length(zContent);
647
+ blob_appendf(pOut, "%.*s\n", n, zContent);
648
+ free(zContent);
649
+ }
650
+ blob_appendf(pOut, "%s\n", zDelim);
651
+}
652
+
653
+/*
654
+** COMMAND: test-tktconfig-export
655
+** Write the current ticket configuration out to a file.
656
+*/
657
+void tktconfig_render_cmd(void){
658
+ Blob config;
659
+
660
+ db_must_be_within_tree();
661
+ if( g.argc!=3 ){
662
+ usage("FILENAME");
663
+ }
664
+ blob_zero(&config);
665
+ ticket_config_render(&config);
666
+ blob_write_to_file(&config, g.argv[2]);
667
+ blob_reset(&config);
668
+}
566669
--- src/tktconf.c
+++ src/tktconf.c
@@ -152,19 +152,19 @@
152 ** the tktfield table and to insert template text into the
153 ** config table
154 */
155 blob_appendf(&tbldef,
156 "DROP TABLE IF EXISTS ticket;\n"
157 "CREATE TABLE ticket(\n"
158 " tktid INTEGER PRIMARY KEY,\n"
159 " tktuuid TEXT UNIQUE,\n"
160 " starttime DATETIME,\n"
161 " lastmod DATETIME"
162 );
163 blob_appendf(&sql,
164 "DROP TABLE IF EXISTS tktfield;\n"
165 "CREATE TABLE tktfield(\n"
166 " fidx INTEGER PRIMARY KEY,\n"
167 " name TEXT UNIQUE,\n"
168 " type TEXT,\n"
169 " width INTEGER,\n"
170 " arg\n"
@@ -308,11 +308,10 @@
308 ** <text>
309 */
310 if( blob_eq(&token, "description")
311 && blob_token(&line, &arg)
312 ){
313 int idx;
314 Blob content;
315 int start;
316 int end;
317
318 start = end = blob_tell(pConfig);
@@ -367,18 +366,36 @@
367 }
368
369 /*
370 ** COMMAND: test-tktconfig-parse
371 */
372 void test_tktconfig_cmd(void){
373 Blob config, err;
374 if( g.argc!=3 ){
375 usage("FILENAME");
376 }
377 blob_read_from_file(&config, g.argv[2]);
378 blob_zero(&err);
379 ticket_config_parse(&config, 1, &err);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380 if( blob_size(&err) ){
381 blob_write_to_file(&err, "-");
382 }
383 }
384
@@ -561,5 +578,91 @@
561 if( blob_size(&errmsg) ){
562 fossil_fatal("%b", &errmsg);
563 }
564 db_end_transaction(0);
565 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
566
--- src/tktconf.c
+++ src/tktconf.c
@@ -152,19 +152,19 @@
152 ** the tktfield table and to insert template text into the
153 ** config table
154 */
155 blob_appendf(&tbldef,
156 "DROP TABLE IF EXISTS ticket;\n"
157 "CREATE TABLE repository.ticket(\n"
158 " tktid INTEGER PRIMARY KEY,\n"
159 " tktuuid TEXT UNIQUE,\n"
160 " starttime DATETIME,\n"
161 " lastmod DATETIME"
162 );
163 blob_appendf(&sql,
164 "DROP TABLE IF EXISTS tktfield;\n"
165 "CREATE TABLE repository.tktfield(\n"
166 " fidx INTEGER PRIMARY KEY,\n"
167 " name TEXT UNIQUE,\n"
168 " type TEXT,\n"
169 " width INTEGER,\n"
170 " arg\n"
@@ -308,11 +308,10 @@
308 ** <text>
309 */
310 if( blob_eq(&token, "description")
311 && blob_token(&line, &arg)
312 ){
 
313 Blob content;
314 int start;
315 int end;
316
317 start = end = blob_tell(pConfig);
@@ -367,18 +366,36 @@
366 }
367
368 /*
369 ** COMMAND: test-tktconfig-parse
370 */
371 void test_tktconfig_parse_cmd(void){
372 Blob config, err;
373 if( g.argc!=3 ){
374 usage("FILENAME");
375 }
376 blob_read_from_file(&config, g.argv[2]);
377 blob_zero(&err);
378 ticket_config_parse(&config, 1, &err);
379 if( blob_size(&err) ){
380 blob_write_to_file(&err, "-");
381 }
382 }
383 /*
384 ** COMMAND: test-tktconfig-import
385 */
386 void test_tktconfig_import_cmd(void){
387 Blob config, err;
388 db_must_be_within_tree();
389 if( g.argc!=3 ){
390 usage("FILENAME");
391 }
392 blob_read_from_file(&config, g.argv[2]);
393 blob_zero(&err);
394 db_begin_transaction();
395 ticket_config_parse(&config, 0, &err);
396 db_end_transaction(0);
397 if( blob_size(&err) ){
398 blob_write_to_file(&err, "-");
399 }
400 }
401
@@ -561,5 +578,91 @@
578 if( blob_size(&errmsg) ){
579 fossil_fatal("%b", &errmsg);
580 }
581 db_end_transaction(0);
582 }
583
584 /*
585 ** Return the length of a string without its trailing whitespace.
586 */
587 static int non_whitespace_length(const char *z){
588 int n = strlen(z);
589 while( n>0 && isspace(z[n-1]) ){ n--; }
590 return n;
591 }
592
593 /*
594 ** Fill the given Blob with text that describes the current
595 ** ticket configuration. This is the inverse of ticket_config_parse()
596 */
597 void ticket_config_render(Blob *pOut){
598 char *zDelim;
599 char *zContent;
600 Stmt q;
601 int n;
602
603 blob_appendf(pOut, "ticket-configuration\n");
604 zDelim = db_text(0, "SELECT '--end-of-text--' || hex(random(20))");
605 blob_appendf(pOut, "###################################################\n");
606 db_prepare(&q, "SELECT name, type, width, arg FROM tktfield");
607 while( db_step(&q)==SQLITE_ROW ){
608 const char *zName = db_column_text(&q, 0);
609 const char *zType = db_column_text(&q, 1);
610 int width = db_column_int(&q, 2);
611 const char *zArg = db_column_text(&q, 3);
612 blob_appendf(pOut, "field %s %s %d %s\n", zName, zType, width, zArg);
613 }
614 db_finalize(&q);
615 blob_appendf(pOut, "###################################################\n");
616 blob_appendf(pOut, "template new %s\n", zDelim);
617 zContent = db_get("tkt-new-template", 0);
618 if( zContent ){
619 n = non_whitespace_length(zContent);
620 blob_appendf(pOut, "%.*s\n", n, zContent);
621 free(zContent);
622 }
623 blob_appendf(pOut, "%s\n", zDelim);
624 blob_appendf(pOut, "###################################################\n");
625 blob_appendf(pOut, "template edit %s\n", zDelim);
626 zContent = db_get("tkt-edit-template", 0);
627 if( zContent ){
628 n = non_whitespace_length(zContent);
629 blob_appendf(pOut, "%.*s\n", n, zContent);
630 free(zContent);
631 }
632 blob_appendf(pOut, "%s\n", zDelim);
633 blob_appendf(pOut, "###################################################\n");
634 blob_appendf(pOut, "template view %s\n", zDelim);
635 zContent = db_get("tkt-view-template", 0);
636 if( zContent ){
637 n = non_whitespace_length(zContent);
638 blob_appendf(pOut, "%.*s\n", n, zContent);
639 free(zContent);
640 }
641 blob_appendf(pOut, "%s\n", zDelim);
642 blob_appendf(pOut, "###################################################\n");
643 blob_appendf(pOut, "description %s\n", zDelim);
644 zContent = db_get("tkt-desc", 0);
645 if( zContent ){
646 n = non_whitespace_length(zContent);
647 blob_appendf(pOut, "%.*s\n", n, zContent);
648 free(zContent);
649 }
650 blob_appendf(pOut, "%s\n", zDelim);
651 }
652
653 /*
654 ** COMMAND: test-tktconfig-export
655 ** Write the current ticket configuration out to a file.
656 */
657 void tktconfig_render_cmd(void){
658 Blob config;
659
660 db_must_be_within_tree();
661 if( g.argc!=3 ){
662 usage("FILENAME");
663 }
664 blob_zero(&config);
665 ticket_config_render(&config);
666 blob_write_to_file(&config, g.argv[2]);
667 blob_reset(&config);
668 }
669
+62 -7
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -44,34 +44,89 @@
4444
"Load a predefined ticket configuration");
4545
setup_menu_entry("Save", "tktsetup_save",
4646
"Save the current ticket configuration as an artifact");
4747
setup_menu_entry("Fields", "tktsetup_fields",
4848
"View or edit the fields allowed in tickets");
49
- setup_menu_entry("New", "tktsetup_newtemplate",
49
+ setup_menu_entry("New", "tktsetup_template?type=new",
5050
"View or edit the template page used for creating a new ticket");
51
- setup_menu_entry("View", "tktsetup_viewtemplate",
51
+ setup_menu_entry("View", "tktsetup_template?type=view",
5252
"View or edit the template page used for viewing a ticket");
53
- setup_menu_entry("Edit", "tktsetup_edittemplate",
53
+ setup_menu_entry("Edit", "tktsetup_template?type=edit",
5454
"View or edit the template page used for editing a ticket");
5555
@ </dl>
5656
5757
style_footer();
5858
}
59
+
60
+/*
61
+** Load the ticket configuration in the artifact with rid.
62
+** If an error occurs, return 1 and leave an error message.
63
+*/
64
+static int load_config(int rid, Blob *pErr){
65
+ Blob content;
66
+ int rc;
67
+ if( content_get(rid, &content)==0 ){
68
+ blob_appendf(pErr, "no such artifact: %d", rid);
69
+ return 1;
70
+ }
71
+ rc = ticket_config_parse(&content, 0, pErr);
72
+ blob_reset(&content);
73
+ return rc;
74
+}
5975
6076
/*
6177
** WEBPAGE: /tktsetup_load
6278
*/
6379
void tktsetup_load_page(void){
6480
int loadrid;
65
- int loaddflt;
81
+ Blob err;
82
+ Stmt s;
6683
6784
login_check_credentials();
6885
if( !g.okSetup ){
6986
login_needed();
7087
}
71
- loadrid = atoi(PD("id","0"));
72
- loaddflt = P("dflt")!=0;
73
- if( loaddflt ){
88
+ if( P("dflt")!=0 ){
7489
ticket_load_default_config();
7590
cgi_redirect("tktsetup");
7691
}
92
+ loadrid = atoi(PD("id","0"));
93
+ blob_zero(&err);
94
+ if( loadrid ){
95
+ if( load_config(loadrid, &err) ){
96
+ style_header("Configuration Error");
97
+ @ <p>The following error occurred while trying to load
98
+ @ the configuration in artifact #%d(loadrid):</p>
99
+ @ <blockquote><b>%h(blob_str(&err))</b></blockquote>
100
+ @ <p>Return to the <a href="tktsetup">ticket setup menu</a>.</p>
101
+ style_footer();
102
+ }else{
103
+ cgi_redirect("tktsetup");
104
+ }
105
+ return;
106
+ }
107
+ style_header("Load Configuration");
108
+ @ <p>Select one of the following ticket configurations to load:</p>
109
+ @ <ul>
110
+ @ <li><p>[<a href="tktsetup_load?dflt=1">default</a>]
111
+ @ The default built-in ticket configuration.</p></li>
112
+ db_prepare(&s,
113
+ "SELECT blob.uuid, tagxref.rid, datetime(tagxref.mtime, 'localtime')"
114
+ " FROM tagxref, blob"
115
+ " WHERE tagxref.tagid=(SELECT tagid FROM tag "
116
+ "WHERE tagname='ticket_configuration')"
117
+ " AND blob.rid=tagxref.rid"
118
+ " ORDER BY tagxref.mtime DESC"
119
+ );
120
+ while( db_step(&s)==SQLITE_ROW ){
121
+ const char *zUuid = db_column_text(&s, 0);
122
+ int rid = db_column_int(&s, 1);
123
+ const char *zWhen = db_column_text(&s, 2);
124
+ @ <li><p>[<a href="tktsetup_load?id=%d(rid)">%s(zUuid)</a>].
125
+ @ Configuration created on %s(zWhen).</p></li>
126
+ }
127
+ db_finalize(&s);
128
+ @ <li><p>[<a href="tktsetup">Cancel</a>]. Return to the main
129
+ @ ticket configuration setup menu.</p></li>
130
+ @ </ul>
131
+ style_footer();
77132
}
78133
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -44,34 +44,89 @@
44 "Load a predefined ticket configuration");
45 setup_menu_entry("Save", "tktsetup_save",
46 "Save the current ticket configuration as an artifact");
47 setup_menu_entry("Fields", "tktsetup_fields",
48 "View or edit the fields allowed in tickets");
49 setup_menu_entry("New", "tktsetup_newtemplate",
50 "View or edit the template page used for creating a new ticket");
51 setup_menu_entry("View", "tktsetup_viewtemplate",
52 "View or edit the template page used for viewing a ticket");
53 setup_menu_entry("Edit", "tktsetup_edittemplate",
54 "View or edit the template page used for editing a ticket");
55 @ </dl>
56
57 style_footer();
58 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
60 /*
61 ** WEBPAGE: /tktsetup_load
62 */
63 void tktsetup_load_page(void){
64 int loadrid;
65 int loaddflt;
 
66
67 login_check_credentials();
68 if( !g.okSetup ){
69 login_needed();
70 }
71 loadrid = atoi(PD("id","0"));
72 loaddflt = P("dflt")!=0;
73 if( loaddflt ){
74 ticket_load_default_config();
75 cgi_redirect("tktsetup");
76 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77 }
78
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -44,34 +44,89 @@
44 "Load a predefined ticket configuration");
45 setup_menu_entry("Save", "tktsetup_save",
46 "Save the current ticket configuration as an artifact");
47 setup_menu_entry("Fields", "tktsetup_fields",
48 "View or edit the fields allowed in tickets");
49 setup_menu_entry("New", "tktsetup_template?type=new",
50 "View or edit the template page used for creating a new ticket");
51 setup_menu_entry("View", "tktsetup_template?type=view",
52 "View or edit the template page used for viewing a ticket");
53 setup_menu_entry("Edit", "tktsetup_template?type=edit",
54 "View or edit the template page used for editing a ticket");
55 @ </dl>
56
57 style_footer();
58 }
59
60 /*
61 ** Load the ticket configuration in the artifact with rid.
62 ** If an error occurs, return 1 and leave an error message.
63 */
64 static int load_config(int rid, Blob *pErr){
65 Blob content;
66 int rc;
67 if( content_get(rid, &content)==0 ){
68 blob_appendf(pErr, "no such artifact: %d", rid);
69 return 1;
70 }
71 rc = ticket_config_parse(&content, 0, pErr);
72 blob_reset(&content);
73 return rc;
74 }
75
76 /*
77 ** WEBPAGE: /tktsetup_load
78 */
79 void tktsetup_load_page(void){
80 int loadrid;
81 Blob err;
82 Stmt s;
83
84 login_check_credentials();
85 if( !g.okSetup ){
86 login_needed();
87 }
88 if( P("dflt")!=0 ){
 
 
89 ticket_load_default_config();
90 cgi_redirect("tktsetup");
91 }
92 loadrid = atoi(PD("id","0"));
93 blob_zero(&err);
94 if( loadrid ){
95 if( load_config(loadrid, &err) ){
96 style_header("Configuration Error");
97 @ <p>The following error occurred while trying to load
98 @ the configuration in artifact #%d(loadrid):</p>
99 @ <blockquote><b>%h(blob_str(&err))</b></blockquote>
100 @ <p>Return to the <a href="tktsetup">ticket setup menu</a>.</p>
101 style_footer();
102 }else{
103 cgi_redirect("tktsetup");
104 }
105 return;
106 }
107 style_header("Load Configuration");
108 @ <p>Select one of the following ticket configurations to load:</p>
109 @ <ul>
110 @ <li><p>[<a href="tktsetup_load?dflt=1">default</a>]
111 @ The default built-in ticket configuration.</p></li>
112 db_prepare(&s,
113 "SELECT blob.uuid, tagxref.rid, datetime(tagxref.mtime, 'localtime')"
114 " FROM tagxref, blob"
115 " WHERE tagxref.tagid=(SELECT tagid FROM tag "
116 "WHERE tagname='ticket_configuration')"
117 " AND blob.rid=tagxref.rid"
118 " ORDER BY tagxref.mtime DESC"
119 );
120 while( db_step(&s)==SQLITE_ROW ){
121 const char *zUuid = db_column_text(&s, 0);
122 int rid = db_column_int(&s, 1);
123 const char *zWhen = db_column_text(&s, 2);
124 @ <li><p>[<a href="tktsetup_load?id=%d(rid)">%s(zUuid)</a>].
125 @ Configuration created on %s(zWhen).</p></li>
126 }
127 db_finalize(&s);
128 @ <li><p>[<a href="tktsetup">Cancel</a>]. Return to the main
129 @ ticket configuration setup menu.</p></li>
130 @ </ul>
131 style_footer();
132 }
133

Keyboard Shortcuts

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