Skip to content

Commit f88f492

Browse files
authored
Merge pull request #45 from LCOGT/feature/gcn-email
Feature/gcn email
2 parents 68f3175 + 1155074 commit f88f492

File tree

3 files changed

+120
-6
lines changed

3 files changed

+120
-6
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<template>
2+
<div>
3+
<b-button :href="dataAsEncodedStr" :download="downloadFilename" v-bind="extraDownloadButtonAttrs">
4+
<slot name="download-button-content"> <i class="fa fa-download" /> {{ downloadText }} </slot>
5+
</b-button>
6+
<pre>{{ getData }}</pre>
7+
</div>
8+
</template>
9+
<script>
10+
export default {
11+
name: 'DataView',
12+
props: {
13+
data: {
14+
type: [ Object , String ],
15+
required: true
16+
},
17+
extraDownloadButtonAttrs: {
18+
type: Object,
19+
default: () => {
20+
return {};
21+
}
22+
},
23+
downloadText: {
24+
type: String,
25+
default: 'Download as JSON'
26+
},
27+
downloadFilename: {
28+
type: String,
29+
default: 'apiview.json'
30+
}
31+
},
32+
computed: {
33+
getData() {
34+
if (typeof this.data == Object){
35+
return JSON.stringify(this.data, null, 4);
36+
}
37+
else{
38+
return this.data;
39+
}
40+
41+
},
42+
dataAsEncodedStr() {
43+
if (typeof this.data == Object){
44+
return 'data:application/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(this.data));
45+
}
46+
else {
47+
return 'data:test/plain;charset=utf-8,' + encodeURIComponent(this.data);
48+
}
49+
}
50+
}
51+
};
52+
</script>
53+

src/components/message-composition/HermesMessage.vue

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@
7676
@input="update"
7777
> Submit to MPC
7878
</b-form-checkbox> -->
79+
<b-form-checkbox
80+
id="submit-to-gcn"
81+
v-model="hermesMessage.submit_to_gcn"
82+
name="submit-to-gcn"
83+
switch
84+
@input="update"
85+
> Submit to GCN
86+
</b-form-checkbox>
7987
</b-col>
8088
</b-form-row>
8189
</b-form>
@@ -340,9 +348,27 @@
340348
<b-container class="p-0 mt-2">
341349
<b-form-row>
342350
<b-col class="bg-light rounded">
343-
<ocs-request-group-api-display
351+
<data-view
344352
class="p-4"
345-
:request-group="this.sanitizedMessageData()"
353+
:data="this.sanitizedMessageData()"
354+
:extra-download-button-attrs="{ class: 'float-right', variant: 'primary' }"
355+
/>
356+
</b-col>
357+
</b-form-row>
358+
</b-container>
359+
</b-tab>
360+
<b-tab @click="generatePlainText">
361+
<template slot="title">
362+
<span><i class="fas fa-code" /> Text View</span>
363+
</template>
364+
<b-container class="p-0 mt-2">
365+
<b-form-row>
366+
<b-col class="bg-light rounded">
367+
<data-view
368+
class="p-4"
369+
:data="plainText"
370+
downloadText="Download Plaintext"
371+
downloadFilename="textview.txt"
346372
:extra-download-button-attrs="{ class: 'float-right', variant: 'primary' }"
347373
/>
348374
</b-col>
@@ -360,6 +386,7 @@
360386
import DataReference from '@/components/message-composition/DataReference.vue'
361387
import DataTable from '@/components/message-composition/DataTable.vue'
362388
import DataTarget from '@/components/message-composition/DataTarget.vue'
389+
import DataView from '@/components/message-composition/DataView.vue'
363390
import DataPhotometry from '@/components/message-composition/DataPhotometry.vue'
364391
import DataSpectroscopy from '@/components/message-composition/DataSpectroscopy.vue'
365392
import DataAstrometry from '@/components/message-composition/DataAstrometry.vue'
@@ -376,7 +403,8 @@
376403
DataTarget,
377404
DataPhotometry,
378405
DataSpectroscopy,
379-
DataAstrometry
406+
DataAstrometry,
407+
DataView
380408
},
381409
mixins: [messageFormatMixin],
382410
props: {
@@ -387,6 +415,10 @@
387415
hermesMessage: {
388416
type: Object,
389417
required: true
418+
},
419+
plainText: {
420+
type: String,
421+
required: true
390422
}
391423
},
392424
data: function () {
@@ -845,6 +877,9 @@
845877
}
846878
this.update();
847879
},
880+
generatePlainText: function() {
881+
this.$emit('generate-plain-text');
882+
},
848883
getDataErrorsArray: function (section, idx) {
849884
return _.get(this.getErrors('data', {}), [section, idx], {});
850885
},

src/components/message-composition/MessageCompositionForm.vue

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<b-container>
33
<b-row>
44
<b-col class="m-0 p-0">
5-
<hermes-message :errors="validationErrors" :hermes-message="hermesMessage"
6-
@hermes-message-updated="hermesMessageUpdated">
5+
<hermes-message :errors="validationErrors" :hermes-message="hermesMessage" :plain-text="plainText"
6+
@hermes-message-updated="hermesMessageUpdated" @generate-plain-text="generatePlainText">
77
</hermes-message>
88
</b-col>
99
</b-row>
@@ -52,6 +52,7 @@ export default {
5252
submitter: '',
5353
submit_to_tns: false,
5454
submit_to_mpc: false,
55+
submit_to_gcn: false,
5556
data: {
5657
event_id: null,
5758
references: [],
@@ -67,7 +68,8 @@ export default {
6768
"submissionEndpoint": String,
6869
},
6970
data: function() {
70-
return {
71+
return {
72+
plainText: '',
7173
topicOptions: [],
7274
validateRequestManager: new OCSUtil.mostRecentRequestManager(this.getValidationRequest, this.onValidationSuccess, this.onValidationFail),
7375
validationErrors: {},
@@ -110,6 +112,29 @@ export default {
110112
this.logout();
111113
}
112114
},
115+
generatePlainText: function() {
116+
let payload = this.sanitizedMessageData();
117+
// Post message via axios
118+
axios({
119+
method: 'post',
120+
withCredentials: true,
121+
// TODO: see if Vue.js can add the X-CSRFToken to all headers automagically
122+
headers: {'Content-Type': 'application/json',
123+
'X-CSRFToken': this.getCsrfToken
124+
},
125+
url: new URL('/api/v0/' + this.submissionEndpoint + '/plaintext/', this.getHermesUrl).href,
126+
data: JSON.stringify(payload)
127+
})
128+
.then((response) => {
129+
this.plainText = response.data;
130+
})
131+
.catch(error => {
132+
console.log(error);
133+
if (error.response.status == 401){
134+
this.logout();
135+
}
136+
});
137+
},
113138
submitToHop() {
114139
let payload = this.sanitizedMessageData();
115140
// Post message via axios
@@ -143,6 +168,7 @@ export default {
143168
this.hermesMessage.submitter = this.getUserName;
144169
this.hermesMessage.submit_to_tns = false;
145170
this.hermesMessage.submit_to_mpc = false;
171+
this.hermesMessage.submit_to_gcn = false;
146172
this.hermesMessage.data = {
147173
event_id: null,
148174
references: [],

0 commit comments

Comments
 (0)