alchemy-chimera 1.3.0-alpha.4 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The chimera-run-task-button element
3
+ * A button that triggers the SystemTask#run API to run a task manually
4
+ *
5
+ * @author Jelle De Loecker <jelle@elevenways.be>
6
+ * @since 1.3.0
7
+ * @version 1.3.0
8
+ */
9
+ const RunTaskButton = Function.inherits('Alchemy.Element.Form.Button', 'Alchemy.Element.Chimera', 'RunTaskButton');
10
+
11
+ /**
12
+ * Set the custom element prefix to 'chimera'
13
+ *
14
+ * @author Jelle De Loecker <jelle@elevenways.be>
15
+ * @since 1.3.0
16
+ * @version 1.3.0
17
+ */
18
+ RunTaskButton.setStatic('custom_element_prefix', 'chimera');
19
+
20
+ /**
21
+ * The task ID to run
22
+ *
23
+ * @author Jelle De Loecker <jelle@elevenways.be>
24
+ * @since 1.3.0
25
+ * @version 1.3.0
26
+ */
27
+ RunTaskButton.setAttribute('task-id');
28
+
29
+ /**
30
+ * The element has been added to the dom for the first time
31
+ *
32
+ * @author Jelle De Loecker <jelle@elevenways.be>
33
+ * @since 1.3.0
34
+ * @version 1.3.0
35
+ */
36
+ RunTaskButton.setMethod(function introduced() {
37
+
38
+ // Call parent introduced first (sets up click/keyup listeners)
39
+ introduced.super.call(this);
40
+
41
+ // Listen to the activate event (emitted by parent Button class on click)
42
+ this.addEventListener('activate', async e => {
43
+ await this.runTask();
44
+ });
45
+ });
46
+
47
+ /**
48
+ * Run the task via API
49
+ *
50
+ * @author Jelle De Loecker <jelle@elevenways.be>
51
+ * @since 1.3.0
52
+ * @version 1.3.0
53
+ */
54
+ RunTaskButton.setMethod(async function runTask() {
55
+
56
+ let task_id = this.task_id;
57
+
58
+ if (!task_id) {
59
+ console.error('No task ID provided');
60
+ return;
61
+ }
62
+
63
+ this.setState('busy');
64
+
65
+ try {
66
+ let result = await this.hawkejs_helpers.Alchemy.getResource({
67
+ name : 'Chimera.SystemTask#run',
68
+ method : 'post',
69
+ }, {
70
+ _id: task_id,
71
+ });
72
+
73
+ this.setState('done');
74
+
75
+ // Redirect to the task monitor page if we have a task history ID
76
+ if (result && result.task_history_id) {
77
+ // Construct the URL for the task monitor page
78
+ let monitor_url = alchemy.routeUrl('Chimera.Editor#taskMonitor', {
79
+ task_history_id: result.task_history_id
80
+ });
81
+
82
+ // Navigate to the monitor page
83
+ if (Blast.isBrowser && typeof hawkejs !== 'undefined' && hawkejs.scene) {
84
+ hawkejs.scene.openUrl(monitor_url);
85
+ } else {
86
+ window.location.href = monitor_url;
87
+ }
88
+ }
89
+ } catch (err) {
90
+ console.error('Failed to run task:', err);
91
+ this.setState('error', 3000, 'default');
92
+ }
93
+ });