-
Notifications
You must be signed in to change notification settings - Fork 0
/
exporthtmljs.pas
203 lines (168 loc) · 6.31 KB
/
exporthtmljs.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
unit exportHtmlJS;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, items, configuration, utils, utils_date;
procedure Export_HtmlJS(fname:string; list : TList; config : TConfig; stGlobal : String);
implementation
procedure Export_HtmlJS(fname:string; list : TList; config : TConfig; stGlobal : String);
var
f: TextFile;
lastProject, sd, sp, sproj, sl : string;
lastDate : TDateTime;
i,sc : integer;
item: PItem;
first:boolean;
begin
lastDate:=-1; //unused value
lastProject:='%µ£'; //unused value
first:=true;
sc:=0; //section counter
AssignFile(f,fname);
try
Rewrite(f);
writeln(f, '<!doctype html>');
writeln(f, '<html lang="fr">');
writeln(f, ' <head>');
writeln(f, ' <meta charset="utf-8">');
writeln(f, ' <title>Titre de la page</title>');
writeln(f, ' <style>');
writeln(f, ' .plus {');
writeln(f, ' background-color: white;');
writeln(f, ' color: black;');
writeln(f, ' cursor: pointer;');
writeln(f, ' }');
writeln(f, ' .title {');
writeln(f, ' font-family: "Verdana","Arial";');
writeln(f, ' font-weight: bold;');
writeln(f, ' }');
writeln(f, ' .p0 {');
writeln(f, ' font-family: "Verdana","Arial";');
writeln(f, ' color:black;');
writeln(f, ' }');
writeln(f, ' .p1 {');
writeln(f, ' font-family: "Verdana","Arial";');
writeln(f, ' color:coral;');
writeln(f, ' }');
writeln(f, ' .p2 {');
writeln(f, ' font-family: "Verdana","Arial";');
writeln(f, ' color:red;');
writeln(f, ' }');
writeln(f, ' .ended{');
writeln(f, ' font-family: "Verdana","Arial";');
writeln(f, ' color: yellowgreen;');
writeln(f, ' }');
writeln(f, ' .project{');
writeln(f, ' font-family: "Verdana","Arial";');
writeln(f, ' background-color: dimgray;');
writeln(f, ' color: white;');
writeln(f, ' }');
writeln(f, ' li {');
writeln(f, ' display: block;');
writeln(f, ' font-family: "Verdana","Arial";');
writeln(f, ' }');
writeln(f, ' </style>');
writeln(f, ' </head>');
writeln(f, ' <body>');
writeln(f, ' <ul>');
for i := 0 to itemList.Count - 1 do
begin
item := PItem(itemList.Items[i]);
if Config.DisplayMode=DISPLAY_PROJECTS then begin
if lastProject<>item^.project then begin
if item^.project='' then
sd:= UpCaseFirstChar(stGlobal)
else
sd:=UpCaseFirstChar(item^.project);
inc(sc);
if first=false then begin
writeln(f, ' </ul>');
writeln(f, ' </li>');
end;
writeln(f, ' <li><span id="section'+intToStr(sc)+'" class="plus">⨀</span> <span class="title">'+sd+'</span>');
writeln(f, ' <ul id="ulsection'+intToStr(sc)+'">');
lastProject:=item^.project;
first:=false;
end;
end
else if Config.DisplayMode=DISPLAY_TIMELINE then begin
if lastDate<>item^.endDate then begin
if item^.endDate=0 then
sd:='Sans date de fin'
else
sd:=UpCaseFirstChar(FormatDateTime('dddd dd mmmm yyyy',item^.endDate));
//--
inc(sc);
if first=false then begin
writeln(f, ' </ul>');
writeln(f, ' </li>');
end;
writeln(f, ' <li><span id="section'+intToStr(sc)+'" class="plus">⨀</span> <span class="title">'+sd+'</span>');
writeln(f, ' <ul id="ulsection'+intToStr(sc)+'">');
lastDate:=item^.endDate;
first:=false;
end;
end;
if item^.progress<>100 then
sp:='p'+IntToStr(item^.priority)
else
sp:='ended';
//-- Notes
if item^.itemType = ITEM_NOTE then
begin
if item^.project<>'' then
sproj:=' ['+item^.project+']'
else
sproj:='';
writeln(f, ' <li class="'+sp+'">⯈ '+ item^.Text + sproj+ '</li>');
end //Notes
//-- Tasks
else if item^.itemType = ITEM_TASK then
begin
if (item^.project<>'') and (config.DisplayMode=DISPLAY_TIMELINE) then
sproj:=' <span class="project"> '+item^.project+' </span>'
else
sproj:='';
if item^.progress<>100 then
sl:='☐'
else
sl:='☑';
if (item^.endDate<>0) and (config.DisplayMode=DISPLAY_PROJECTS) then
sd:=' <span>◷</span>'+FormatDateTimeEx(ToFormatDate(config.DateOrder), item^.endDate)
else
sd:='';
writeln(f, ' <li class="'+sp+'">'+sl+' '+intToStr(item^.progress)+'%'+sd+'⯈ '+ item^.Text + sproj+ '</li>');
end; //Tasks
end; //for
if first=false then begin
writeln(f, ' </ul>');
writeln(f, ' </li>');
end;
writeln(f, ' </ul>');
writeln(f, ' <script>');
writeln(f, ' function HideShow(el,item) {');
writeln(f, ' if (el.textContent=="\u2A00") {');
writeln(f, ' el.textContent="\u2A01";');
writeln(f, ' document.getElementById(item).style.display="none";');
writeln(f, ' }');
writeln(f, ' else {');
writeln(f, ' el.textContent="\u2A00";');
writeln(f, ' document.getElementById(item).style.display="block";');
writeln(f, ' }');
writeln(f, ' }');
for i:=1 to sc do begin
writeln(f, '');
writeln(f, ' document.getElementById("section'+intToStr(i)+'").addEventListener("click",');
writeln(f, ' function() {HideShow(this,"ulsection'+intToStr(i)+'");}');
writeln(f, ' , false);');
end;
writeln(f, ' </script>');
writeln(f, ' </body>');
writeln(f, '</html>');
CloseFile(f);
except
on E: EInOutError do
writeln('Error while exporting the list as HTML+JS. Details: ', E.Message);
end;
end;
end.