| Total Complexity | 6 |
| Complexity/F | 1 |
| Lines of Code | 63 |
| Function Count | 6 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import {chat_v1 as chatV1} from 'googleapis/build/src/apis/chat/v1'; |
||
| 2 | |||
| 3 | interface Card { |
||
| 4 | buildHeader?(): void; |
||
| 5 | |||
| 6 | buildSections(): void; |
||
| 7 | |||
| 8 | buildButtons?(): void; |
||
| 9 | |||
| 10 | buildFooter?(): void; |
||
| 11 | |||
| 12 | create(): chatV1.Schema$GoogleAppsCardV1Card; |
||
| 13 | |||
| 14 | createCardWithId(): chatV1.Schema$CardWithId; |
||
| 15 | |||
| 16 | createMessage(): chatV1.Schema$Message; |
||
| 17 | } |
||
| 18 | |||
| 19 | export default abstract class BaseCard implements Card { |
||
| 20 | protected id: string = 'cardId'; |
||
| 21 | private _content: chatV1.Schema$GoogleAppsCardV1Section[] = []; |
||
| 22 | |||
| 23 | protected card: chatV1.Schema$GoogleAppsCardV1Card = { |
||
| 24 | sections: this._content, |
||
| 25 | }; |
||
| 26 | |||
| 27 | protected createButton( |
||
| 28 | text: string, action: string, interaction: string | undefined = undefined, |
||
| 29 | parameters = []): chatV1.Schema$GoogleAppsCardV1Button { |
||
| 30 | const button: chatV1.Schema$GoogleAppsCardV1Button = { |
||
| 31 | text, |
||
| 32 | 'onClick': { |
||
| 33 | 'action': { |
||
| 34 | 'function': action, |
||
| 35 | }, |
||
| 36 | }, |
||
| 37 | }; |
||
| 38 | interaction && (button.onClick!.action!.interaction = interaction); |
||
| 39 | parameters.length && (button.onClick!.action!.parameters = parameters); |
||
| 40 | return button; |
||
| 41 | } |
||
| 42 | |||
| 43 | protected addSectionWidget(widget: chatV1.Schema$GoogleAppsCardV1Widget) { |
||
| 44 | this.card.sections!.push({widgets: [widget]}); |
||
| 45 | } |
||
| 46 | |||
| 47 | abstract buildSections(): void; |
||
| 48 | |||
| 49 | abstract create(): chatV1.Schema$GoogleAppsCardV1Card; |
||
| 50 | |||
| 51 | |||
| 52 | createCardWithId(): chatV1.Schema$CardWithId { |
||
| 53 | return { |
||
| 54 | 'cardId': this.id, |
||
| 55 | 'card': this.create(), |
||
| 56 | }; |
||
| 57 | } |
||
| 58 | |||
| 59 | createMessage(): chatV1.Schema$Message { |
||
| 60 | return {cardsV2: [this.createCardWithId()]}; |
||
| 61 | } |
||
| 62 | } |
||
| 63 |