Skip to content

Commit 6d040d8

Browse files
authored
Merge pull request #13 from observatorycontrolsystem/fix/get_profile_before_routing
Set groundwork to fix data inspector issues
2 parents 104825c + f9aa4a2 commit 6d040d8

3 files changed

Lines changed: 31 additions & 29 deletions

File tree

src/App.vue

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<b-alert v-if="profileError" show variant="danger" dismissible @dismissed="profileError = ''">
5353
<p>{{ profileError }}</p>
5454
</b-alert>
55-
<router-view class="my-3" />
55+
<router-view class="my-3" v-if="!loading"/>
5656
</b-container>
5757
<ArchiveFooter
5858
:copyright-organization="this.$store.state.urls.copyrightOrganization"
@@ -75,7 +75,8 @@ export default {
7575
},
7676
data: function() {
7777
return {
78-
profileError: ''
78+
profileError: '',
79+
loading: true
7980
};
8081
},
8182
computed: {
@@ -89,16 +90,16 @@ export default {
8990
return this.userIsAuthenticated && this.profile.profile.proposals.length < 1;
9091
}
9192
},
92-
created: function () {
93-
this.$store
94-
.dispatch('getProfileData')
95-
.then(() => {
96-
this.profileError = '';
97-
})
98-
.catch((response) => {
99-
this.profileError= `Failed to load profile data - ${response.status}: ${response.statusText} - ${response.responseText}`;
100-
console.error(this.profileError);
101-
});
93+
created: async function () {
94+
try {
95+
await this.$store.dispatch('getProfileData');
96+
this.profileError = '';
97+
} catch (response) {
98+
this.profileError= `Failed to load profile data - ${response.status}: ${response.statusText} - ${response.responseText}`;
99+
console.error(this.profileError);
100+
} finally {
101+
this.loading = false;
102+
}
102103
},
103104
methods: {
104105
logout: function() {

src/router/index.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import VueRouter from 'vue-router';
33
import Home from '../views/Home.vue';
44
import Login from '../views/Login.vue';
55
import NotFound from '../components/NotFound.vue';
6-
import store from '../store';
76

87
Vue.use(VueRouter);
98

@@ -12,21 +11,6 @@ const routes = [
1211
path: '/',
1312
name: 'Home',
1413
component: Home,
15-
beforeEnter: (to, from, next) => {
16-
// if the route contains a public parameter, honor that
17-
if (to.query.public != undefined) {
18-
next();
19-
return
20-
}
21-
22-
// otherwise send authenticated users to public=false
23-
// and unauthenticated users to public=true
24-
if (store.state.userIsAuthenticated) {
25-
next({ name: 'Home', query: {...to.query, public: "false"}});
26-
} else {
27-
next({ name: 'Home', query: {...to.query, public: "true"}});
28-
}
29-
}
3014
},
3115
{
3216
path: '/login',

src/views/Home.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ export default {
2626
let now = moment.utc().format('YYYY-MM-DD HH:mm');
2727
return `${this.$store.state.urls.observationPortalApiUrl}/semesters/?start_lte=${now}`;
2828
}
29-
}
29+
},
30+
created: function () {
31+
// if the route contains a public parameter, honor that
32+
if (this.$route.query.public == undefined) {
33+
let newQueryParams = {...this.$route.query};
34+
if (this.$store.state.userIsAuthenticated) {
35+
newQueryParams.public = "false";
36+
}
37+
else {
38+
// anonymous users should see public data and science data by default
39+
newQueryParams.public = "true";
40+
}
41+
this.$router.replace({
42+
path: this.$route.path,
43+
query: newQueryParams
44+
});
45+
}
46+
},
3047
};
3148
</script>

0 commit comments

Comments
 (0)