diff --git a/extensions/Squidex.Extensions/Actions/Discourse/DiscourseAction.cs b/extensions/Squidex.Extensions/Actions/Discourse/DiscourseAction.cs index b082130e4..4711dec26 100644 --- a/extensions/Squidex.Extensions/Actions/Discourse/DiscourseAction.cs +++ b/extensions/Squidex.Extensions/Actions/Discourse/DiscourseAction.cs @@ -27,9 +27,13 @@ namespace Squidex.Extensions.Actions.Discourse public Uri Url { get; set; } [Required] - [Display(Name = "Api Key", Description = "The api key.")] + [Display(Name = "Api Key", Description = "The api key to authenticate to your discourse server.")] public string ApiKey { get; set; } + [Required] + [Display(Name = "Api Username", Description = "The api username to authenticate to your discourse server.")] + public string ApiUsername { get; set; } + [Required] [Display(Name = "Text", Description = "The text as markdown.")] public string Text { get; set; } diff --git a/extensions/Squidex.Extensions/Actions/Discourse/DiscourseActionHandler.cs b/extensions/Squidex.Extensions/Actions/Discourse/DiscourseActionHandler.cs index efd2e6c57..cf5a32f4a 100644 --- a/extensions/Squidex.Extensions/Actions/Discourse/DiscourseActionHandler.cs +++ b/extensions/Squidex.Extensions/Actions/Discourse/DiscourseActionHandler.cs @@ -7,14 +7,20 @@ using System; using System.Net.Http; +using System.Text; using System.Threading.Tasks; +using Newtonsoft.Json.Linq; using Squidex.Domain.Apps.Core.HandleRules; +using Squidex.Domain.Apps.Core.HandleRules.Actions.Utils; using Squidex.Domain.Apps.Core.HandleRules.EnrichedEvents; namespace Squidex.Extensions.Actions.Discourse { public sealed class DiscourseActionHandler : RuleActionHandler { + private const string DescriptionCreatePost = "Create discourse Post"; + private const string DescriptionCreateTopic = "Create discourse Topic"; + private readonly IHttpClientFactory httpClientFactory; public DiscourseActionHandler(RuleEventFormatter formatter, IHttpClientFactory httpClientFactory) @@ -23,19 +29,50 @@ namespace Squidex.Extensions.Actions.Discourse this.httpClientFactory = httpClientFactory; } - protected override Task<(string Description, DiscourseJob Data)> CreateJobAsync(EnrichedEvent @event, DiscourseAction action) + protected override (string Description, DiscourseJob Data) CreateJob(EnrichedEvent @event, DiscourseAction action) { - return base.CreateJobAsync(@event, action); + var url = $"{action.Url.ToString().TrimEnd('/')}/posts.json?api_key={action.ApiKey}&api_username={action.ApiUsername}"; + + var json = + new JObject( + new JProperty("raw", Format(action.Text, @event)), + new JProperty("title", Format(action.Title, @event))); + + if (action.Topic.HasValue) + { + json.Add(new JProperty("topic_id", action.Topic.Value)); + } + + if (action.Category.HasValue) + { + json.Add(new JProperty("category", action.Category.Value)); + } + + var ruleJob = new DiscourseJob + { + RequestUrl = url, + RequestBody = json.ToString() + }; + + var description = + action.Topic.HasValue ? + DescriptionCreateTopic : + DescriptionCreatePost; + + return (description, ruleJob); } - protected override Task<(string Dump, Exception Exception)> ExecuteJobAsync(DiscourseJob job) + protected override async Task<(string Dump, Exception Exception)> ExecuteJobAsync(DiscourseJob job) { - using (var client = httpClientFactory.CreateClient()) + using (var httpClient = httpClientFactory.CreateClient()) { - // Foo - } + var request = new HttpRequestMessage(HttpMethod.Post, job.RequestUrl) + { + Content = new StringContent(job.RequestBody, Encoding.UTF8, "application/json") + }; - return Task.FromResult<(string Dump, Exception Exception)>((string.Empty, null)); + return await httpClient.OneWayRequestAsync(request, job.RequestBody); + } } } diff --git a/src/Squidex/app/features/rules/declarations.ts b/src/Squidex/app/features/rules/declarations.ts index dc84c2e69..daa7be5b8 100644 --- a/src/Squidex/app/features/rules/declarations.ts +++ b/src/Squidex/app/features/rules/declarations.ts @@ -5,6 +5,16 @@ * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. */ +export * from './pages/rules/actions/algolia-action.component'; +export * from './pages/rules/actions/azure-queue-action.component'; +export * from './pages/rules/actions/discourse-action.component'; +export * from './pages/rules/actions/elastic-search-action.component'; +export * from './pages/rules/actions/fastly-action.component'; +export * from './pages/rules/actions/medium-action.component'; +export * from './pages/rules/actions/slack-action.component'; +export * from './pages/rules/actions/tweet-action.component'; +export * from './pages/rules/actions/webhook-action.component'; + export * from './pages/rules/triggers/asset-changed-trigger.component'; export * from './pages/rules/triggers/content-changed-trigger.component'; diff --git a/src/Squidex/app/features/rules/module.ts b/src/Squidex/app/features/rules/module.ts index 2a5eb9999..cb13812c0 100644 --- a/src/Squidex/app/features/rules/module.ts +++ b/src/Squidex/app/features/rules/module.ts @@ -14,18 +14,23 @@ import { SqxSharedModule } from '@app/shared'; -import * as actions from './pages/rules/actions'; - -const actionTypes: any = Object.values(actions); - import { + AlgoliaActionComponent, AssetChangedTriggerComponent, + AzureQueueActionComponent, ContentChangedTriggerComponent, + DiscourseActionComponent, + ElasticSearchActionComponent, + FastlyActionComponent, + MediumActionComponent, RuleElementComponent, RuleEventBadgeClassPipe, RuleEventsPageComponent, RulesPageComponent, - RuleWizardComponent + RuleWizardComponent, + SlackActionComponent, + TweetActionComponent, + WebhookActionComponent } from './declarations'; const routes: Routes = [ @@ -55,14 +60,22 @@ const routes: Routes = [ RouterModule.forChild(routes) ], declarations: [ - ...actionTypes, + AlgoliaActionComponent, AssetChangedTriggerComponent, + AzureQueueActionComponent, ContentChangedTriggerComponent, + DiscourseActionComponent, + ElasticSearchActionComponent, + FastlyActionComponent, + MediumActionComponent, RuleElementComponent, RuleEventBadgeClassPipe, RuleEventsPageComponent, RulesPageComponent, - RuleWizardComponent + RuleWizardComponent, + SlackActionComponent, + TweetActionComponent, + WebhookActionComponent ] }) export class SqxFeatureRulesModule { } \ No newline at end of file diff --git a/src/Squidex/app/features/rules/pages/rules/actions/algolia-action.component.html b/src/Squidex/app/features/rules/pages/rules/actions/algolia-action.component.html index eb4f635de..473d82410 100644 --- a/src/Squidex/app/features/rules/pages/rules/actions/algolia-action.component.html +++ b/src/Squidex/app/features/rules/pages/rules/actions/algolia-action.component.html @@ -1,5 +1,3 @@ -

Populate index in algolia with content

-
diff --git a/src/Squidex/app/features/rules/pages/rules/actions/azure-queue-action.component.html b/src/Squidex/app/features/rules/pages/rules/actions/azure-queue-action.component.html index e6bb28b9a..3f0b9229a 100644 --- a/src/Squidex/app/features/rules/pages/rules/actions/azure-queue-action.component.html +++ b/src/Squidex/app/features/rules/pages/rules/actions/azure-queue-action.component.html @@ -1,5 +1,3 @@ -

Send event payload to Azure Storage Queue

-
diff --git a/src/Squidex/app/features/rules/pages/rules/actions/discourse-action.component.html b/src/Squidex/app/features/rules/pages/rules/actions/discourse-action.component.html new file mode 100644 index 000000000..0e5245f63 --- /dev/null +++ b/src/Squidex/app/features/rules/pages/rules/actions/discourse-action.component.html @@ -0,0 +1,99 @@ +
+
+ + +
+ + + + + + The url where the events will be sent to. + +
+
+ +
+ + +
+ + + + + + The api key to authenticate to your discourse server. + +
+
+ +
+ + +
+ + + + + + The api username to authenticate to your discourse server. + +
+
+ +
+ + +
+ + + + + + The text for your topic or post. Read the help section for information about advanced formatting. + +
+
+ +
+ + +
+ + + + + + The optional title, when you want to create a topic. Read the help section for information about advanced formatting. + +
+
+ +
+ + +
+ + + + + + The topic id when you want to create a post. + +
+
+ +
+ + +
+ + + + + + The category id when you create a topic. + +
+
+
\ No newline at end of file diff --git a/src/Squidex/app/features/rules/pages/rules/actions/discourse-action.component.scss b/src/Squidex/app/features/rules/pages/rules/actions/discourse-action.component.scss new file mode 100644 index 000000000..756609665 --- /dev/null +++ b/src/Squidex/app/features/rules/pages/rules/actions/discourse-action.component.scss @@ -0,0 +1,6 @@ +@import '_vars'; +@import '_mixins'; + +textarea { + height: 150px; +} \ No newline at end of file diff --git a/src/Squidex/app/features/rules/pages/rules/actions/discourse-action.component.ts b/src/Squidex/app/features/rules/pages/rules/actions/discourse-action.component.ts new file mode 100644 index 000000000..a2e25ac55 --- /dev/null +++ b/src/Squidex/app/features/rules/pages/rules/actions/discourse-action.component.ts @@ -0,0 +1,56 @@ +/* + * Squidex Headless CMS + * + * @license + * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. + */ + +import { Component, Input, OnInit } from '@angular/core'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; + +@Component({ + selector: 'sqx-discourse-action', + styleUrls: ['./discourse-action.component.scss'], + templateUrl: './discourse-action.component.html' +}) +export class DiscourseActionComponent implements OnInit { + @Input() + public action: any; + + @Input() + public actionForm: FormGroup; + + @Input() + public actionFormSubmitted = false; + + public ngOnInit() { + this.actionForm.setControl('url', + new FormControl(this.action.url || '', [ + Validators.required + ])); + + this.actionForm.setControl('apiKey', + new FormControl(this.action.apiKey || '', [ + Validators.required + ])); + + this.actionForm.setControl('apiUsername', + new FormControl(this.action.apiUsername || '', [ + Validators.required + ])); + + this.actionForm.setControl('text', + new FormControl(this.action.text || '', [ + Validators.required + ])); + + this.actionForm.setControl('title', + new FormControl(this.action.title)); + + this.actionForm.setControl('topic', + new FormControl(this.action.topic)); + + this.actionForm.setControl('category', + new FormControl(this.action.category)); + } +} \ No newline at end of file diff --git a/src/Squidex/app/features/rules/pages/rules/actions/elastic-search-action.component.html b/src/Squidex/app/features/rules/pages/rules/actions/elastic-search-action.component.html index 70a61536b..7c6f5468e 100644 --- a/src/Squidex/app/features/rules/pages/rules/actions/elastic-search-action.component.html +++ b/src/Squidex/app/features/rules/pages/rules/actions/elastic-search-action.component.html @@ -1,5 +1,3 @@ -

Populate index in ElasticSearch with content

-
diff --git a/src/Squidex/app/features/rules/pages/rules/actions/fastly-action.component.html b/src/Squidex/app/features/rules/pages/rules/actions/fastly-action.component.html index 8d5b59fae..9354a9834 100644 --- a/src/Squidex/app/features/rules/pages/rules/actions/fastly-action.component.html +++ b/src/Squidex/app/features/rules/pages/rules/actions/fastly-action.component.html @@ -1,5 +1,3 @@ -

Purge cache entries in Fastly

-
diff --git a/src/Squidex/app/features/rules/pages/rules/actions/index.ts b/src/Squidex/app/features/rules/pages/rules/actions/index.ts deleted file mode 100644 index 5fa30c3a4..000000000 --- a/src/Squidex/app/features/rules/pages/rules/actions/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Squidex Headless CMS - * - * @license - * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. - */ - -export * from './algolia-action.component'; -export * from './azure-queue-action.component'; -export * from './elastic-search-action.component'; -export * from './fastly-action.component'; -export * from './medium-action.component'; -export * from './slack-action.component'; -export * from './tweet-action.component'; -export * from './webhook-action.component'; diff --git a/src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.html b/src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.html index b5861bcef..c342c9849 100644 --- a/src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.html +++ b/src/Squidex/app/features/rules/pages/rules/actions/medium-action.component.html @@ -1,5 +1,3 @@ -

Post to Medium

-
diff --git a/src/Squidex/app/features/rules/pages/rules/actions/slack-action.component.html b/src/Squidex/app/features/rules/pages/rules/actions/slack-action.component.html index 508a9e908..6ff2466f9 100644 --- a/src/Squidex/app/features/rules/pages/rules/actions/slack-action.component.html +++ b/src/Squidex/app/features/rules/pages/rules/actions/slack-action.component.html @@ -1,5 +1,3 @@ -

Send custom text to an incoming webhook in Slack

-
diff --git a/src/Squidex/app/features/rules/pages/rules/actions/tweet-action.component.html b/src/Squidex/app/features/rules/pages/rules/actions/tweet-action.component.html index 6b0909bd4..449d56fa4 100644 --- a/src/Squidex/app/features/rules/pages/rules/actions/tweet-action.component.html +++ b/src/Squidex/app/features/rules/pages/rules/actions/tweet-action.component.html @@ -1,5 +1,3 @@ -

Tweet a status update to your twitter feed

-
diff --git a/src/Squidex/app/features/rules/pages/rules/actions/webhook-action.component.html b/src/Squidex/app/features/rules/pages/rules/actions/webhook-action.component.html index 18845041e..c998a021a 100644 --- a/src/Squidex/app/features/rules/pages/rules/actions/webhook-action.component.html +++ b/src/Squidex/app/features/rules/pages/rules/actions/webhook-action.component.html @@ -1,5 +1,3 @@ -

Send event payload to webhook

-
diff --git a/src/Squidex/app/features/rules/pages/rules/rule-element.component.scss b/src/Squidex/app/features/rules/pages/rules/rule-element.component.scss index 2b61ad9ce..9696ca52a 100644 --- a/src/Squidex/app/features/rules/pages/rules/rule-element.component.scss +++ b/src/Squidex/app/features/rules/pages/rules/rule-element.component.scss @@ -42,14 +42,16 @@ max-height: 100px; } - &-title { - font-weight: bold; - } - &-link { font-size: .8rem; } + &-title { + font-weight: bold; + font-size: 1rem; + line-height: 1; + } + &-text { font-size: .8rem; margin-top: .25rem; diff --git a/src/Squidex/app/features/rules/pages/rules/rule-wizard.component.html b/src/Squidex/app/features/rules/pages/rules/rule-wizard.component.html index 0cd61f345..8da18c6df 100644 --- a/src/Squidex/app/features/rules/pages/rules/rule-wizard.component.html +++ b/src/Squidex/app/features/rules/pages/rules/rule-wizard.component.html @@ -31,6 +31,8 @@ +

{{ruleTriggers[triggerType].display}}

+ +

{{ruleActions[actionType].display}}

+ + + + + Trigger rule when events happen for assets... -
diff --git a/src/Squidex/app/features/rules/pages/rules/triggers/content-changed-trigger.component.html b/src/Squidex/app/features/rules/pages/rules/triggers/content-changed-trigger.component.html index 248c620d8..10c6037cb 100644 --- a/src/Squidex/app/features/rules/pages/rules/triggers/content-changed-trigger.component.html +++ b/src/Squidex/app/features/rules/pages/rules/triggers/content-changed-trigger.component.html @@ -1,5 +1,3 @@ -

Trigger rule when events happen for schemas...

-