source: trunk/Pages/PageAdmin.pas

Last change on this file was 151, checked in by chronos, 9 months ago
File size: 4.5 KB
Line 
1unit PageAdmin;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, WebPage, HTTPServer;
7
8type
9
10 { TPageAdmin }
11
12 TPageAdmin = class(TWebPage)
13 procedure DataModuleProduce(HandlerData: THTTPHandlerData);
14 private
15 procedure HandleReload(HandlerData: THTTPHandlerData);
16 procedure HandleModuleList(HandlerData: THTTPHandlerData);
17 procedure HandleInstall(HandlerData: THTTPHandlerData);
18 procedure HandleUninstall(HandlerData: THTTPHandlerData);
19 end;
20
21var
22 PageAdmin: TPageAdmin;
23
24const
25 BooleanText: array[Boolean] of string = ('No', 'Yes');
26
27
28implementation
29
30uses
31 Core, XmlClasses, HtmlClasses, Utils, SqlDatabase, ModularSystem,
32 ModuleSystem, WebSession;
33
34{$R *.lfm}
35
36{ TPageAdmin }
37
38procedure TPageAdmin.DataModuleProduce(HandlerData: THTTPHandlerData);
39var
40 TextBlock: THtmlString;
41 I: Integer;
42 PageName: string;
43begin
44 with TWebSession(HandlerData) do begin
45 if Request.Path.Count > 1 then PageName := Request.Path[1]
46 else PageName := '';
47 with HtmlDocument.Body do begin
48 if PageName = '' then PageName := 'modulelist';
49 if PageName = 'modulelist' then HandleModuleList(HandlerData)
50 else if PageName = 'reload' then HandleReload(HandlerData)
51 else if PageName = 'install' then HandleInstall(HandlerData)
52 else if PageName = 'uninstall' then HandleUninstall(HandlerData);
53 end;
54 GeneratePage(Self);
55 end;
56end;
57
58procedure TPageAdmin.HandleReload(HandlerData: THTTPHandlerData);
59begin
60 with TWebSession(HandlerData) do begin
61 with HtmlDocument.Body, SubItems.AddString do begin
62 TModuleSystem(ModuleManager.FindModuleByName('System')).UpdateModuleList;
63 Text := 'Seznam modulů synchronizován';
64 Text := Text + '<br/><br/>';
65 HandleModuleList(HandlerData);
66 end;
67 end;
68end;
69
70procedure TPageAdmin.HandleModuleList(HandlerData: THTTPHandlerData);
71var
72 TextBlock: THtmlString;
73 I: Integer;
74begin
75 with TWebSession(HandlerData) do begin
76 with HtmlDocument.Body, SubItems.AddString do begin
77 Text := Text + '<strong>Registred modules:</strong><br/>' +
78 '<table class="WideTable"><tr><th>Name</th><th>Installed</th><th>Title</th><th>Version</th>' +
79 '<th>License</th><th>Author</th><th>Decsription</th><th>Dependencies</th><th>Actions</th></tr>';
80 for I := 0 to ModuleManager.Modules.Count - 1 do
81 with TModule(ModuleManager.Modules[I]) do begin
82 Text := Text + '<tr><td>' + Identification + '</td><td>' + BooleanText[Installed] + '</td><td>' + Title +
83 '</td><td>' + Version + '</td><td>' + License + '</td><td>' + Author +
84 '</td><td>' + Description.Text + '</td><td>' + Dependencies.Text + '</td><td>';
85 if Installed then Text := Text + MakeLink('Uninstall', NavigationLink('/administration/uninstall?name=' + Identification))
86 else Text := Text + MakeLink('Install', NavigationLink('/administration/install?name=' + Identification));
87 Text := Text + '</td></tr>';
88 end;
89 Text := Text + '</table>';
90 Text := Text + MakeLink('Obnovit seznam modulů', NavigationLink('/administration/reload'));
91 end;
92 end;
93end;
94
95procedure TPageAdmin.HandleInstall(HandlerData: THTTPHandlerData);
96var
97 ModuleName: string;
98 Module: TModule;
99 Name: string;
100begin
101 with TWebSession(HandlerData) do begin
102 with HtmlDocument.Body, SubItems.AddString do begin
103 if Request.Query.TryGetValue('name', Name) then begin
104 ModuleName := Name;
105 Module := ModuleManager.FindModuleByName(ModuleName);
106 if Assigned(Module) then begin
107 Text := 'Installing module ' + ModuleName;
108 Module.Install;
109 Module.Start;
110 end else Text := Text + 'Module ' + ModuleName + ' not found';
111 end else Text := Text + 'Module not specified';
112 Text := Text + '<br/><br/>';
113 HandleModuleList(HandlerData);
114 end;
115 end;
116end;
117
118procedure TPageAdmin.HandleUninstall(HandlerData: THTTPHandlerData);
119var
120 ModuleName: string;
121 Module: TModule;
122 Name: string;
123begin
124 with TWebSession(HandlerData) do begin
125 with HtmlDocument.Body, SubItems.AddString do begin
126 if Request.Query.TryGetValue('name', Name) then begin
127 ModuleName := Name;
128 Module := ModuleManager.FindModuleByName(ModuleName);
129 if Assigned(Module) then begin
130 Text := 'Uninstalling module ' + ModuleName;
131 Module.Uninstall;
132 end else Text := Text + 'Module ' + ModuleName + ' not found';
133 end else Text := Text + 'Module not specified';
134 Text := Text + '<br/><br/>';
135 HandleModuleList(HandlerData);
136 end;
137 end;
138end;
139
140end.
141
Note: See TracBrowser for help on using the repository browser.