-
Notifications
You must be signed in to change notification settings - Fork 14
/
Plugin.cs
80 lines (71 loc) · 2.96 KB
/
Plugin.cs
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
using System.Linq;
using SiteServer.Plugin;
using SS.Form.Core;
using SS.Form.Core.Repositories;
namespace SS.Form
{
public class Plugin : PluginBase
{
public static string PluginVersion;
public override void Startup(IService service)
{
PluginVersion = Version;
var formRepository = new FormRepository();
var fieldRepository = new FieldRepository();
var fieldItemRepository = new FieldItemRepository();
var logRepository = new LogRepository();
service
.AddSiteMenu(siteId =>
{
var formInfoList = FormManager.GetFormInfoList(siteId, 0);
var menus = formInfoList.Where(formInfo => !string.IsNullOrEmpty(formInfo.Title)).Select(formInfo => new Menu
{
Text = FormManager.GetFormTitle(formInfo),
Href = $"pages/logs.html?formId={formInfo.Id}"
}).ToList();
menus.Add(new Menu
{
Text = "表单管理",
Href = "pages/forms.html"
});
menus.Add(new Menu
{
Text = "表单模板",
Href = "pages/templates.html"
});
return new Menu
{
Text = "表单",
IconClass = "ion-android-list",
Menus = menus
};
})
.AddContentMenu(contentInfo =>
{
var formInfo =
FormManager.GetFormInfoByContentId(contentInfo.SiteId, contentInfo.ChannelId, contentInfo.Id);
var menu = new Menu
{
Text = FormManager.GetFormTitle(formInfo),
Href = "pages/logs.html"
};
return menu;
})
.AddDatabaseTable(formRepository.TableName, formRepository.TableColumns)
.AddDatabaseTable(fieldRepository.TableName, fieldRepository.TableColumns)
.AddDatabaseTable(fieldItemRepository.TableName, fieldItemRepository.TableColumns)
.AddDatabaseTable(logRepository.TableName, logRepository.TableColumns)
.AddStlElementParser(StlForm.ElementName, StlForm.Parse)
;
service.ContentDeleteCompleted += Service_ContentDeleteCompleted;
}
private static void Service_ContentDeleteCompleted(object sender, ContentEventArgs e)
{
var formInfo = FormManager.GetFormInfoByContentId(e.SiteId, e.ChannelId, e.ContentId);
if (formInfo != null)
{
FormManager.Repository.Delete(e.SiteId, formInfo.Id);
}
}
}
}