cob-cli 2.20.1 → 2.22.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.
@@ -23,59 +23,43 @@ export default {
23
23
  name: 'App',
24
24
  components: { Dashboard },
25
25
  data: () => ({
26
- userInfo: null,
27
- name: null,
28
26
  error: "",
27
+ userInfo: null,
28
+ dashboardName: null,
29
29
  dashboardInstance: null,
30
- dashboardInstanceId: Number,
31
30
  dashboardParsed: null,
32
31
  dashboardState: "Loading"
33
32
  }),
34
33
  created() {
35
34
  // At the initial load we get the dashboard instance name from the url
36
35
  umLoggedin().then( userInfo => {
37
- let name = document.getElementsByClassName("custom-resource")[0].getAttribute('data-name').split(":")[0]
38
- this.dashboardInstance = instancesList(DASHBOARD_DEF, this.getDashboardQuery(name, userInfo), 1)
36
+ this.userInfo = userInfo
37
+ this.dashboardName = document.getElementsByClassName("custom-resource")[0].getAttribute('data-name').split(":")[0]
38
+ this.dashboardInstance = instancesList(DASHBOARD_DEF, this.dashboardQuery, 1 /*just get the first*/)
39
39
  })
40
40
 
41
41
  // Upon anchor navigation we get the dashboard instance name from the first param to the 'resume' callback.
42
42
  $('section.custom-resource').on('resume', (e, params) => {
43
43
  //Recheck user (the user might have changed or his groups might have changed after previous load)
44
44
  umLoggedin().then(userInfo => {
45
- let name = params[0].split(":")[0]
46
- if( name !== this.name || this.userInfo.username !== userInfo.username ){
47
- this.dashboardInstance.changeArgs({query: this.getDashboardQuery(name, userInfo) })
48
- }
45
+ let name = params[0].split(":")[0]
46
+ if( name !== this.dashboardName || this.userInfo.username !== userInfo.username ){
47
+ this.userInfo = userInfo
48
+ this.dashboardName = name
49
+ this.dashboardInstance.changeArgs({query: this.dashboardQuery })
50
+ }
49
51
  })
50
52
  });
51
53
  },
54
+ computed: {
55
+ dashboardQuery() {
56
+ let groups = this.userInfo.groups.map(g=> "\"" + g.name + "\"").join(" OR ")
57
+ let nameQuery = "name.raw:\"" + this.dashboardName + "\" "
58
+ let accessQuery = " (groupaccess.raw:(" + groups + ") OR (-groupaccess:*) )"
59
+ return "(" + nameQuery + accessQuery +") OR id:" + this.dashboardName
60
+ }
61
+ },
52
62
  watch: {
53
- // Monitor changes to the id of the Dashboard instance
54
- dashboardInstanceId(newInstanceId) {
55
- axios
56
- .get("/recordm/recordm/instances/" + newInstanceId)
57
- .then(resp => {
58
- try {
59
- this.dashboardParsed = parseDashboard(resp.data, this.userInfo)
60
- this.dashboardState = "Ready"
61
- }
62
- catch(e) {
63
- this.error = "Error: error parsing dashboard " + newInstanceId + " (" + e + ")"
64
- this.dashboardState = "Error"
65
- console.error(e)
66
- }
67
- })
68
- .catch( (e) => {
69
- if( e.response && e.response.status && e.response.status === 403) {
70
- this.error = "New authorization required..."
71
- } else {
72
- this.error = "Error: error getting dashboard " + newInstanceId
73
- }
74
- this.dashboardState = "Error"
75
- console.error(e)
76
- })
77
- },
78
-
79
63
  // Monitor state changes to the searching of the Dashboard instance
80
64
  'dashboardInstance.state'(instanceInfoState) {
81
65
  if(instanceInfoState === "loading" || instanceInfoState === "updating") {
@@ -103,30 +87,38 @@ export default {
103
87
  },
104
88
 
105
89
  // Monitor value changes to the values of the Dashboard instance
106
- 'dashboardInstance.value'(newDashboards) {
107
- if(newDashboards.length === 0) {
90
+ 'dashboardInstance.value'(newDashboard) {
91
+ if(newDashboard.length === 0) {
108
92
  this.dashboardState = "Error"
109
- this.error = "Error: dashboard '" + this.name + "' was not found for your user"
93
+ this.error = "Error: dashboard '" + this.dashboardName + "' was not found for your user"
110
94
  } else {
111
- //Instance(s) found (from ES). Use the 1st result.
112
- this.dashboardInstanceId = newDashboards[0].id
95
+ //Instance found (from ES) (we only asked for the 1st match)
96
+ let newInstanceId = newDashboard[0].id
97
+ axios.get("/recordm/recordm/instances/" + newInstanceId)
98
+ .then(resp => {
99
+ try {
100
+ this.dashboardParsed = parseDashboard(resp.data, this.userInfo)
101
+ this.dashboardState = "Ready"
102
+ //Set the page title
103
+ document.title = "Recordm[" + this.dashboardName + "]"
104
+ }
105
+ catch(e) {
106
+ this.error = "Error: error parsing dashboard " + newInstanceId + " (" + e + ")"
107
+ this.dashboardState = "Error"
108
+ console.error(e)
109
+ }
110
+ })
111
+ .catch( (e) => {
112
+ if( e.response && e.response.status && e.response.status === 403) {
113
+ this.error = "New authorization required..."
114
+ } else {
115
+ this.error = "Error: error getting dashboard " + newInstanceId
116
+ }
117
+ this.dashboardState = "Error"
118
+ console.error(e)
119
+ })
113
120
  }
114
121
  }
115
- },
116
- methods: {
117
- getDashboardQuery(name, userInfo) {
118
- this.userInfo = userInfo
119
- this.name = name
120
-
121
- // TODO this is wrong we should only set the dashboard name after we pull it from recordm.
122
- // there is no guarantee that dashboard exists
123
- document.title = "Recordm[" + name + "]"
124
- let groups = userInfo.groups.map(g=> "\"" + g.name + "\"").join(" OR ")
125
-
126
- let nameQuery = "name.raw:\"" + name + "\" "
127
- let accessQuery = " (groupaccess.raw:(" + groups + ") OR (-groupaccess:*) )"
128
- return "(" + nameQuery + accessQuery +") OR id:" + name
129
- }
130
122
  }
131
123
  };
132
124
  </script>
@@ -5,7 +5,7 @@
5
5
  :class="line.classes"
6
6
  :href="line.link"
7
7
  >
8
- <span style="margin-right: 20px;">
8
+ <span>
9
9
  <i v-if="line.icon" :class="line.icon" style="margin-right:4px"></i>
10
10
  <span v-html="line.text"></span>
11
11
  </span>