-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSlackConfigController.cs
112 lines (100 loc) · 4.38 KB
/
SlackConfigController.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.UI;
using Countersoft.Gemini.Commons.Dto;
using Countersoft.Gemini.Commons.Entity;
using Countersoft.Gemini.Extensibility.Apps;
using Countersoft.Gemini.Infrastructure.Apps;
using Countersoft.Foundation.Commons.Extensions;
namespace TSJ.Gemini.Slack
{
public class AppConstants
{
public const string AppId = "ABBADABB-AD00-4151-A177-1F0529EEE7E1";
}
[AppType(AppTypeEnum.Config),
AppGuid(AppConstants.AppId),
AppControlGuid("D5ED7A38-BE89-403E-8118-E5C3CC8C8E71"),
AppAuthor("Dana Hanna"),
AppKey("SlackIntegration"),
AppName("Slack Connector"),
AppDescription("Provides slack integration by posting updates to gemini to a channel in slack."),
AppRequiresConfigScreen(true)]
[ValidateInput(false)]
[OutputCache(Duration = 0, NoStore = false, Location = OutputCacheLocation.None)]
public class SlackConfigController : BaseAppController
{
public override void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(null, "apps/slack/configure", new { controller = "SlackConfig", action = "GetConfig" });
routes.MapRoute(null, "apps/slack/save", new { controller = "SlackConfig", action = "SaveConfig" });
}
public override WidgetResult Caption(IssueDto issue)
{
WidgetResult result = new WidgetResult();
result.Success = true;
result.Markup.Html = "Slack Integration";
return result;
}
public override WidgetResult Show(IssueDto args)
{
var result = new WidgetResult();
result.Success = true;
result.Markup.Html = "Slack Integration";
return result;
}
public override WidgetResult Configuration()
{
var model = new SlackConfigModel();
try
{
var data = GeminiContext.GlobalConfigurationWidgetStore.Get<SlackConfigData>(AppConstants.AppId);
if (data != null && data.Value != null)
{
model.SlackUrl = data.Value.SlackAPIEndpoint;
if (data.Value.ProjectChannels != null && data.Value.ProjectChannels.ContainsKey(0))
{
model.Channel = data.Value.ProjectChannels[0];
}
model.SecondsToQueueChanges = data.Value.SecondsToQueueChanges == 0 ? 60 : data.Value.SecondsToQueueChanges;
}
} catch
{ }
var projects = GeminiContext.Projects.GetAll();
projects.Insert(0, new Project() { Id = 0, Name = GetResource(Countersoft.Gemini.ResourceKeys.AllProjects) });
model.Projects = new SelectList(projects, "Id", "Name", 0);
var result = new WidgetResult();
result.Success = true;
result.Markup = new WidgetMarkup("views/Settings.cshtml", model);
return result;
}
public ActionResult SaveConfig(string SlackUrl, int project, string channel, int secondsToQueueChanges)
{
var data = GeminiContext.GlobalConfigurationWidgetStore.Get<SlackConfigData>(AppConstants.AppId);
var saveData = data != null && data.Value != null ? data.Value : new SlackConfigData();
saveData.SlackAPIEndpoint = SlackUrl;
saveData.ProjectChannels[project] = channel;
saveData.SecondsToQueueChanges = secondsToQueueChanges;
GeminiContext.GlobalConfigurationWidgetStore.Save<SlackConfigData>(AppConstants.AppId, saveData);
return JsonSuccess();
}
public ActionResult GetConfig(int projectId)
{
var data = GeminiContext.GlobalConfigurationWidgetStore.Get<SlackConfigData>(AppConstants.AppId);
string channel = "";
if (data != null && data.Value != null)
{
if (data.Value.ProjectChannels.ContainsKey(projectId))
{
channel = data.Value.ProjectChannels[projectId];
}
}
return JsonSuccess(new { Channel = channel });
}
}
}