Skip to content

Commit

Permalink
Use unified SettingsCallsign
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Oct 15, 2024
1 parent 24a6877 commit baef21c
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 108 deletions.
6 changes: 5 additions & 1 deletion api/routes/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Auth from '../lib/auth.js';
import { ProfileResponse } from '../lib/types.js'
import Config from '../lib/config.js';
import { TAKRole, TAKGroup } from '../lib/api/types.js'
import { sql } from 'drizzle-orm';
import { Profile_Text, Profile_Stale, Profile_Speed, Profile_Elevation, Profile_Distance } from '../lib/enums.js';

export default async function router(schema: Schema, config: Config) {
Expand Down Expand Up @@ -46,7 +47,10 @@ export default async function router(schema: Schema, config: Config) {
}, async (req, res) => {
try {
const user = await Auth.as_user(config, req);
const profile = await config.models.Profile.commit(user.email, req.body);
const profile = await config.models.Profile.commit(user.email, {
...req.body,
updated: sql`Now()`
});

return res.json(profile);
} catch (err) {
Expand Down
10 changes: 6 additions & 4 deletions api/web/src/components/CloudTAK/Map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
<Loading v-if='loading.main || !isLoaded' />

<template v-if='isLoaded && !loading.main'>
<WarnChannels
v-if='warnChannels'
@close='warnChannels = false'
/>
<WarnConfiguration v-if='warnConfiguration' @close='warnConfiguration = false' />
<WarnChannels v-else-if='warnChannels' @close='warnChannels = false' />

<div
v-if='profile'
Expand Down Expand Up @@ -462,6 +460,7 @@

<script>
import WarnChannels from './util/WarnChannels.vue';
import WarnConfiguration from './util/WarnConfiguration.vue';
import Status from '../util/Status.vue';
import CoordInput from './CoordInput.vue';
import CoordinateType from './util/CoordinateType.vue';
Expand Down Expand Up @@ -583,6 +582,7 @@ export default {
]);
this.warnChannels = profileStore.hasNoChannels;
this.warnConfiguration = profileStore.hasNoConfiguration;
this.loading.main = false;
Expand Down Expand Up @@ -654,6 +654,7 @@ export default {
height: window.innerHeight,
width: window.innerWidth,
warnChannels: false, // Show a popup if no channels are selected on load
warnConfiguration: false, // Show a popup if role/groups hasn't been set
search: {
shown: false,
filter: '',
Expand Down Expand Up @@ -1018,6 +1019,7 @@ export default {
Status,
CoordInput,
WarnChannels,
WarnConfiguration,
CoordinateType,
SideMenu,
Loading,
Expand Down
106 changes: 3 additions & 103 deletions api/web/src/components/CloudTAK/Menu/SettingsCallsign.vue
Original file line number Diff line number Diff line change
@@ -1,120 +1,20 @@
<template>
<MenuTemplate name='Callsign &amp; Device'>
<div class='mx-2'>
<TablerLoading v-if='loading' />
<template v-else>
<div class='col-12'>
<TablerInput
v-model='profile.tak_callsign'
label='User Callsign'
/>
</div>
<div class='col-12'>
<TablerEnum
v-model='profile.tak_group'
label='User Group'
:options='tak_groups'
/>
</div>
<div class='col-12'>
<TablerEnum
v-model='profile.tak_role'
label='User Role'
:options='tak_roles'
/>
</div>
<div class='col-12 d-flex py-3'>
<div class='ms-auto'>
<button
class='btn btn-primary'
@click='updateProfile'
>
Update
</button>
</div>
</div>
</template>
<SettingsCallsign/>
</div>
</MenuTemplate>
</template>

<script>
import MenuTemplate from '../util/MenuTemplate.vue';
import { std } from '/src/std.ts';
import {
TablerInput,
TablerEnum,
TablerLoading
} from '@tak-ps/vue-tabler';
import { useProfileStore } from '/src/stores/profile.ts';
const profileStore = useProfileStore();
import SettingsCallsign from '../util/SettingsCallsign.vue';
export default {
name: 'CloudTAKSettingsCallsign',
components: {
TablerInput,
TablerEnum,
TablerLoading,
MenuTemplate,
SettingsCallsign
},
data: function() {
return {
loading: true,
profile: {},
config: {}
}
},
computed: {
tak_groups: function() {
const groups = [];
for (const g in this.config.groups) {
if (this.config.groups[g]) {
groups.push(`${g} - ${this.config.groups[g]}`);
} else {
groups.push(g);
}
}
return groups;
},
tak_roles: function() {
return this.config.roles;
}
},
mounted: async function() {
this.loading = true;
await this.fetchConfig();
await profileStore.load();
const profile = JSON.parse(JSON.stringify(profileStore.profile));
if (this.config.groups[profile.tak_group]) {
profile.tak_group = `${profile.tak_group} - ${this.config.groups[profile.tak_group]}`;
}
this.profile = profile;
this.loading = false;
},
methods: {
fetchConfig: async function() {
const config = await std('/api/config/group');
const groups = {};
for (const key in config.groups) {
groups[key.replace('group::', '')] = config.groups[key];
}
this.config = {
groups,
roles: config.roles
};
},
updateProfile: async function() {
const profile = JSON.parse(JSON.stringify(this.profile));
profile.tak_group = profile.tak_group.replace(/\s-\s.*$/, '');
await profileStore.update(profile);
this.$router.push("/menu/settings");
}
}
}
</script>
114 changes: 114 additions & 0 deletions api/web/src/components/CloudTAK/util/SettingsCallsign.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<template>
<TablerLoading v-if='loading' />
<template v-else>
<div class='col-12'>
<TablerInput
v-model='profile.tak_callsign'
label='User Callsign'
/>
</div>
<div class='col-12'>
<TablerEnum
v-model='profile.tak_group'
label='User Group'
:options='tak_groups'
/>
</div>
<div class='col-12'>
<TablerEnum
v-model='profile.tak_role'
label='User Role'
:options='tak_roles'
/>
</div>
<div class='col-12 d-flex py-3'>
<div class='ms-auto'>
<button
class='btn btn-primary'
@click='updateProfile'
>
Update
</button>
</div>
</div>
</template>
</template>

<script>
import { std } from '/src/std.ts';
import {
TablerInput,
TablerEnum,
TablerLoading
} from '@tak-ps/vue-tabler';
import { useProfileStore } from '/src/stores/profile.ts';
const profileStore = useProfileStore();
export default {
name: 'CloudTAKSettingsCallsign',
components: {
TablerInput,
TablerEnum,
TablerLoading,
},
data: function() {
return {
loading: true,
profile: {},
config: {}
}
},
computed: {
tak_groups: function() {
const groups = [];
for (const g in this.config.groups) {
if (this.config.groups[g]) {
groups.push(`${g} - ${this.config.groups[g]}`);
} else {
groups.push(g);
}
}
return groups;
},
tak_roles: function() {
return this.config.roles;
}
},
mounted: async function() {
this.loading = true;
await this.fetchConfig();
await profileStore.load();
const profile = JSON.parse(JSON.stringify(profileStore.profile));
if (this.config.groups[profile.tak_group]) {
profile.tak_group = `${profile.tak_group} - ${this.config.groups[profile.tak_group]}`;
}
this.profile = profile;
this.loading = false;
},
methods: {
fetchConfig: async function() {
const config = await std('/api/config/group');
const groups = {};
for (const key in config.groups) {
groups[key.replace('group::', '')] = config.groups[key];
}
this.config = {
groups,
roles: config.roles
};
},
updateProfile: async function() {
const profile = JSON.parse(JSON.stringify(this.profile));
profile.tak_group = profile.tak_group.replace(/\s-\s.*$/, '');
await profileStore.update(profile);
this.$router.push("/menu/settings");
}
}
}
</script>
52 changes: 52 additions & 0 deletions api/web/src/components/CloudTAK/util/WarnConfiguration.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<TablerModal size='lg'>
<div class='modal-status bg-red' />
<button
type='button'
class='btn-close'
aria-label='Close'
@click='$emit("close")'
/>
<div class='modal-header text-white'>
<div class='d-flex align-items-center'>
<IconInfoSquare
:size='28'
:stroke='1'
/>
<span class='mx-2'>Welcome to CloudTAK</span>
</div>
</div>
<div class='modal-body text-white'>
<SettingsCallsign/>
</div>
</TablerModal>
</template>

<script>
import {
TablerModal,
} from '@tak-ps/vue-tabler';
import {
IconInfoSquare,
} from '@tabler/icons-vue';
import SettingsCallsign from './SettingsCallsign.vue';
export default {
name: 'WarnConfiguration',
components: {
TablerModal,
IconInfoSquare,
SettingsCallsign
},
emits: [
'close'
],
methods: {
selectChannels: function() {
this.$emit('close');
this.$router.push('/menu/channels');
},
}
}
</script>
4 changes: 4 additions & 0 deletions api/web/src/stores/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const useProfileStore = defineStore('profile', {
}

return true;
},
hasNoConfiguration: function(): boolean {
if (!this.profile) return false;
return this.profile.created === this.profile.updated;
}
},
actions: {
Expand Down

0 comments on commit baef21c

Please sign in to comment.