Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/stores/buckets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ export const useBucketsStore = defineStore('buckets', {
(id: string) => !id.startsWith('aw-watcher-android')
);
},
// The window/afk bucket ids to query for a desktop host. Buckets synced
// from another device carry a "-synced-from-<device>" suffix, so the
// "aw-watcher-window_<host>" id only exists for local buckets. Falls back
// to that conventional id when no matching bucket is loaded.
desktopBucketIds(): (host: string) => { bid_window: string; bid_afk: string } {
return host => ({
bid_window: this.bucketsWindow(host)[0] || 'aw-watcher-window_' + host,
bid_afk: this.bucketsAFK(host)[0] || 'aw-watcher-afk_' + host,
});
},
bucketsAndroid(): (host: string) => string[] {
return host => {
const android = this.bucketsByType(host, 'currentwindow').filter((id: string) =>
Expand Down
3 changes: 1 addition & 2 deletions src/views/Alerts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ export default {
// Check current time of alert goals
check: async function () {
let query = canonicalEvents({
bid_window: 'aw-watcher-window_' + this.hostname,
bid_afk: 'aw-watcher-afk_' + this.hostname,
...this.bucketsStore.desktopBucketIds(this.hostname),
filter_afk: this.filter_afk,
categories: useCategoryStore().classes_for_query,
filter_categories: null, // classes.map(c => c[0]),
Expand Down
4 changes: 2 additions & 2 deletions src/views/Graph.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import 'vue-awesome/icons/angle-double-down';
import 'vue-awesome/icons/angle-double-up';

import { canonicalEvents, querystr_to_array } from '~/queries';
import { useBucketsStore } from '~/stores/buckets';

import { useCategoryStore } from '~/stores/categories';

Expand Down Expand Up @@ -109,8 +110,7 @@ export default {
fetchEvents: async function () {
// TODO: use full query (one per day/timeperiod) instead of canonicalEvents
let query = canonicalEvents({
bid_window: 'aw-watcher-window_' + this.queryOptions.hostname,
bid_afk: 'aw-watcher-afk_' + this.queryOptions.hostname,
...useBucketsStore().desktopBucketIds(this.queryOptions.hostname),
filter_afk: this.queryOptions.filter_afk,
categories: this.categoryStore.classes_for_query,
filter_categories: this.excludeUncategorized
Expand Down
3 changes: 1 addition & 2 deletions src/views/Report.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ export default {
generate: async function () {
// TODO: use full query (one per day/timeperiod) instead of canonicalEvents
let query = canonicalEvents({
bid_window: 'aw-watcher-window_' + this.queryOptions.hostname,
bid_afk: 'aw-watcher-afk_' + this.queryOptions.hostname,
...this.bucketsStore.desktopBucketIds(this.queryOptions.hostname),
filter_afk: this.queryOptions.filter_afk,
categories: this.filterCategories,
filter_categories: this.filterCategories.map(c => c[0]),
Expand Down
4 changes: 2 additions & 2 deletions src/views/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ div
import _ from 'lodash';
import moment from 'moment';
import { canonicalEvents, querystr_to_array } from '~/queries';
import { useBucketsStore } from '~/stores/buckets';

import 'vue-awesome/icons/search';
import 'vue-awesome/icons/spinner';
Expand Down Expand Up @@ -69,8 +70,7 @@ export default {
methods: {
search: async function () {
let query = canonicalEvents({
bid_window: 'aw-watcher-window_' + this.queryOptions.hostname,
bid_afk: 'aw-watcher-afk_' + this.queryOptions.hostname,
...useBucketsStore().desktopBucketIds(this.queryOptions.hostname),
filter_afk: this.queryOptions.filter_afk,
categories: [[['searched'], { type: 'regex', regex: this.pattern, ignore_case: true }]],
filter_categories: [['searched']],
Expand Down
3 changes: 1 addition & 2 deletions src/views/Trends.vue
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,7 @@ export default {
const cats = this.categoryStore.classes_for_query;
const code =
canonicalEvents({
bid_window: 'aw-watcher-window_' + this.host,
bid_afk: 'aw-watcher-afk_' + this.host,
...this.bucketsStore.desktopBucketIds(this.host),
filter_afk: true,
categories: cats,
filter_categories: null,
Expand Down
3 changes: 1 addition & 2 deletions src/views/settings/CategoryBuilder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ export default {
};
} else {
bucketParams = {
bid_window: 'aw-watcher-window_' + hostname,
bid_afk: 'aw-watcher-afk_' + hostname,
...bucketsStore.desktopBucketIds(hostname),
filter_afk: this.queryOptions.filter_afk,
};
}
Expand Down
40 changes: 40 additions & 0 deletions test/unit/store/buckets.test.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,43 @@ describe('bucketsByDevice', () => {
expect(device.device_ids).toHaveLength(2);
});
});

describe('desktopBucketIds', () => {
beforeEach(() => {
setActivePinia(createPinia());
});

test('returns the real ids of buckets synced from another device', () => {
const store = useBucketsStore();
store.update_buckets([
bucket({ id: 'aw-watcher-window_erb-m2' }),
bucket({ id: 'aw-watcher-afk_erb-m2', type: 'afkstatus' }),
bucket({
id: 'aw-watcher-window_home-desktop-synced-from-home-desktop',
hostname: 'home-desktop',
}),
bucket({
id: 'aw-watcher-afk_home-desktop-synced-from-home-desktop',
hostname: 'home-desktop',
type: 'afkstatus',
}),
]);

expect(store.desktopBucketIds('home-desktop')).toEqual({
bid_window: 'aw-watcher-window_home-desktop-synced-from-home-desktop',
bid_afk: 'aw-watcher-afk_home-desktop-synced-from-home-desktop',
});
expect(store.desktopBucketIds('erb-m2')).toEqual({
bid_window: 'aw-watcher-window_erb-m2',
bid_afk: 'aw-watcher-afk_erb-m2',
});
});

test('falls back to the conventional ids when no bucket is loaded', () => {
const store = useBucketsStore();
expect(store.desktopBucketIds('laptop')).toEqual({
bid_window: 'aw-watcher-window_laptop',
bid_afk: 'aw-watcher-afk_laptop',
});
});
});
Loading