Skip to content

Commit 36bf4be

Browse files
authored
Merge pull request #33 from iotum/jerry_hu/search-widget
search widget
2 parents 1b50da5 + 97f5dd2 commit 36bf4be

44 files changed

Lines changed: 3505 additions & 2904 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

dist/index.d.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ declare module '@iotum/callbridge-js/dashboard' {
77
export enum Service {
88
/** None */
99
None = "",
10+
/** Search */
11+
Search = "Search",
1012
/** Team (Chat) */
1113
Team = "Team",
1214
/** Drive (Content Library) */
@@ -82,6 +84,9 @@ declare module '@iotum/callbridge-js/dashboard' {
8284
*/
8385
invitedHosts?: number[];
8486
};
87+
/**
88+
* Chat room.
89+
*/
8590
export type ChatRoom = {
8691
/** Room path, used for navigation. @see `Dashboard.load` */
8792
path: string;
@@ -94,6 +99,24 @@ declare module '@iotum/callbridge-js/dashboard' {
9499
picture_url: string;
95100
}>;
96101
};
102+
/**
103+
* Search options.
104+
*/
105+
export type SearchOptions = {
106+
/** The search content type. Default `SearchContentType.Event` */
107+
contentType?: SearchContentType;
108+
/** The page number of the search result. Optional, default 1 */
109+
page?: number;
110+
/** The sorting order of the search result. Optional, default 'date' */
111+
order?: 'date' | 'relevance';
112+
};
113+
/**
114+
* Search content type.
115+
*/
116+
export enum SearchContentType {
117+
/** E.g. meeting and call event. */
118+
event = "event"
119+
}
97120
/**
98121
* Callbridge Dashboard.
99122
*/
@@ -136,6 +159,29 @@ declare module '@iotum/callbridge-js/dashboard' {
136159
id?: number;
137160
options: ScheduleOptions;
138161
};
162+
'dashboard.SEARCH_START': {
163+
/** The search query. */
164+
query: string;
165+
/** The page of the result. */
166+
page: number;
167+
/** The order of the result. */
168+
order: 'date' | 'relevance';
169+
};
170+
'dashboard.SEARCH_RESULT': {
171+
/** The search query. */
172+
query: string;
173+
/** The search error. */
174+
error?: string;
175+
/** The search result. */
176+
result?: Array<{
177+
/** The type of the item. */
178+
contentType: SearchContentType;
179+
/** The id of the item */
180+
id: number;
181+
/** The result text with <mark> */
182+
highlight: Record<string, Array<string>>;
183+
}>;
184+
};
139185
/** Meeting widget is ready */
140186
'room.READY': void;
141187
/** Meeting widget is unloading */
@@ -156,6 +202,15 @@ declare module '@iotum/callbridge-js/dashboard' {
156202
* Optional, service options.
157203
*/
158204
serviceOptions?: ServiceOptions);
205+
/**
206+
* Search for thing.
207+
* @param query The search query.
208+
* @param options Optional, search options.
209+
* @throws {Error}
210+
* - "Not implemented" when the service is not "Search".
211+
* - "Nothing to search" when the query is empty.
212+
*/
213+
search(query: string, options?: SearchOptions): void;
159214
/**
160215
* Loads the service.
161216
* @param service the service to load.
@@ -179,7 +234,7 @@ declare module '@iotum/callbridge-js/dashboard' {
179234
}
180235
declare module '@iotum/callbridge-js/index' {
181236
export { type WidgetOptions } from '@iotum/callbridge-js/widget';
182-
export { default as Dashboard, Service, LayoutOption, MeetingAction, ScheduleAction, type ServiceOptions, type ChatRoom, } from '@iotum/callbridge-js/dashboard';
237+
export { default as Dashboard, Service, LayoutOption, MeetingAction, ScheduleAction, SearchContentType, type ServiceOptions, type ChatRoom, type SearchOptions, } from '@iotum/callbridge-js/dashboard';
183238
export { type AudioSettings } from '@iotum/callbridge-js/room';
184239
export { default as Meeting, type MeetingOptions } from '@iotum/callbridge-js/meeting';
185240
export { default as Livestream, type LivestreamOptions } from '@iotum/callbridge-js/livestream';

dist/index.esm.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ var Widget = class {
122122
this.emit("widget.ERROR", ev instanceof Error ? ev.message : ev);
123123
};
124124
} catch (ex) {
125+
console.warn(ex);
125126
this.emit("widget.ERROR", "Unable to open");
126127
}
127128
};
@@ -307,6 +308,7 @@ var Widget = class {
307308
// src/dashboard.ts
308309
var Service = /* @__PURE__ */ ((Service2) => {
309310
Service2["None"] = "";
311+
Service2["Search"] = "Search";
310312
Service2["Team"] = "Team";
311313
Service2["Drive"] = "Drive";
312314
Service2["Contacts"] = "Contacts";
@@ -331,6 +333,10 @@ var ScheduleAction = /* @__PURE__ */ ((ScheduleAction2) => {
331333
ScheduleAction2["intercept"] = "intercept";
332334
return ScheduleAction2;
333335
})(ScheduleAction || {});
336+
var SearchContentType = /* @__PURE__ */ ((SearchContentType2) => {
337+
SearchContentType2["event"] = "event";
338+
return SearchContentType2;
339+
})(SearchContentType || {});
334340
var Dashboard = class extends Widget {
335341
constructor(options, service = "" /* None */, serviceOptions = {}) {
336342
super(options);
@@ -339,13 +345,44 @@ var Dashboard = class extends Widget {
339345
case "Drive" /* Drive */:
340346
case "Contacts" /* Contacts */:
341347
case "Meet" /* Meet */:
348+
case "Search" /* Search */:
342349
this.once("dashboard.READY", () => this.load(service, serviceOptions));
343350
break;
344351
}
352+
switch (service) {
353+
case "Search" /* Search */:
354+
this.search = (query, {
355+
contentType = "event" /* event */,
356+
...opts
357+
} = {}) => {
358+
if (!query) {
359+
throw new Error("Nothing to search");
360+
}
361+
this._send("dashboard", "search", {
362+
query,
363+
contentType,
364+
...opts
365+
});
366+
};
367+
break;
368+
}
345369
this._load({
346370
redirect_url: `/conf/loading`
347371
});
348372
}
373+
/**
374+
* Search for thing.
375+
* @param query The search query.
376+
* @param options Optional, search options.
377+
* @throws {Error}
378+
* - "Not implemented" when the service is not "Search".
379+
* - "Nothing to search" when the query is empty.
380+
*/
381+
search(query, options) {
382+
query;
383+
options;
384+
throw new Error("Not implemented");
385+
}
349386
/**
350387
* Loads the service.
351388
* @param service the service to load.
@@ -533,5 +570,6 @@ export {
533570
Meeting,
534571
MeetingAction,
535572
ScheduleAction,
573+
SearchContentType,
536574
Service
537575
};

dist/index.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ var __copyProps = (to, from, except, desc) => {
1818
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1919

2020
// src/index.ts
21-
var src_exports = {};
22-
__export(src_exports, {
21+
var index_exports = {};
22+
__export(index_exports, {
2323
Dashboard: () => Dashboard,
2424
LayoutOption: () => LayoutOption,
2525
Livestream: () => Livestream,
2626
Meeting: () => Meeting,
2727
MeetingAction: () => MeetingAction,
2828
ScheduleAction: () => ScheduleAction,
29+
SearchContentType: () => SearchContentType,
2930
Service: () => Service
3031
});
31-
module.exports = __toCommonJS(src_exports);
32+
module.exports = __toCommonJS(index_exports);
3233

3334
// src/widget.ts
3435
var import_events = require("events");
@@ -154,6 +155,7 @@ var Widget = class {
154155
this.emit("widget.ERROR", ev instanceof Error ? ev.message : ev);
155156
};
156157
} catch (ex) {
158+
console.warn(ex);
157159
this.emit("widget.ERROR", "Unable to open");
158160
}
159161
};
@@ -339,6 +341,7 @@ var Widget = class {
339341
// src/dashboard.ts
340342
var Service = /* @__PURE__ */ ((Service2) => {
341343
Service2["None"] = "";
344+
Service2["Search"] = "Search";
342345
Service2["Team"] = "Team";
343346
Service2["Drive"] = "Drive";
344347
Service2["Contacts"] = "Contacts";
@@ -363,6 +366,10 @@ var ScheduleAction = /* @__PURE__ */ ((ScheduleAction2) => {
363366
ScheduleAction2["intercept"] = "intercept";
364367
return ScheduleAction2;
365368
})(ScheduleAction || {});
369+
var SearchContentType = /* @__PURE__ */ ((SearchContentType2) => {
370+
SearchContentType2["event"] = "event";
371+
return SearchContentType2;
372+
})(SearchContentType || {});
366373
var Dashboard = class extends Widget {
367374
constructor(options, service = "" /* None */, serviceOptions = {}) {
368375
super(options);
@@ -371,13 +378,44 @@ var Dashboard = class extends Widget {
371378
case "Drive" /* Drive */:
372379
case "Contacts" /* Contacts */:
373380
case "Meet" /* Meet */:
381+
case "Search" /* Search */:
374382
this.once("dashboard.READY", () => this.load(service, serviceOptions));
375383
break;
376384
}
385+
switch (service) {
386+
case "Search" /* Search */:
387+
this.search = (query, {
388+
contentType = "event" /* event */,
389+
...opts
390+
} = {}) => {
391+
if (!query) {
392+
throw new Error("Nothing to search");
393+
}
394+
this._send("dashboard", "search", {
395+
query,
396+
contentType,
397+
...opts
398+
});
399+
};
400+
break;
401+
}
377402
this._load({
378403
redirect_url: `/conf/loading`
379404
});
380405
}
406+
/**
407+
* Search for thing.
408+
* @param query The search query.
409+
* @param options Optional, search options.
410+
* @throws {Error}
411+
* - "Not implemented" when the service is not "Search".
412+
* - "Nothing to search" when the query is empty.
413+
*/
414+
search(query, options) {
415+
query;
416+
options;
417+
throw new Error("Not implemented");
418+
}
381419
/**
382420
* Loads the service.
383421
* @param service the service to load.
@@ -566,5 +604,6 @@ var Livestream = class extends Widget {
566604
Meeting,
567605
MeetingAction,
568606
ScheduleAction,
607+
SearchContentType,
569608
Service
570609
});

eslint.config.mjs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import typescriptEslint from '@typescript-eslint/eslint-plugin';
2+
import jest from 'eslint-plugin-jest';
3+
import prettier from 'eslint-plugin-prettier';
4+
import globals from 'globals';
5+
import tsParser from '@typescript-eslint/parser';
6+
import path from 'node:path';
7+
import { fileURLToPath } from 'node:url';
8+
import js from '@eslint/js';
9+
import { FlatCompat } from '@eslint/eslintrc';
10+
11+
const __filename = fileURLToPath(import.meta.url);
12+
const __dirname = path.dirname(__filename);
13+
const compat = new FlatCompat({
14+
baseDirectory: __dirname,
15+
recommendedConfig: js.configs.recommended,
16+
allConfig: js.configs.all,
17+
});
18+
19+
/** @type {import('eslint').Linter.Config[]} */
20+
export default [
21+
{
22+
ignores: ['dist/*'],
23+
},
24+
...compat.extends('eslint:recommended', 'plugin:jest/recommended'),
25+
{
26+
plugins: {
27+
'@typescript-eslint': typescriptEslint,
28+
jest,
29+
prettier,
30+
},
31+
32+
languageOptions: {
33+
globals: {
34+
...globals.browser,
35+
require: 'readonly',
36+
},
37+
38+
parser: tsParser,
39+
},
40+
41+
rules: {
42+
'no-unused-vars': 'off',
43+
'@typescript-eslint/no-unused-vars': 'warn',
44+
'prettier/prettier': 'error',
45+
},
46+
},
47+
{
48+
files: ['src/**/*.ts'],
49+
},
50+
];

0 commit comments

Comments
 (0)