Completed
Push — master ( 4fcad4...efcce7 )
by Muhammad Dyas
19s queued 16s
created

src/cards/AddOptionFormCard.ts   A

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 64
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 46
mnd 0
bc 0
fnc 4
dl 0
loc 64
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A AddOptionFormCard.buildSections 0 14 1
A AddOptionFormCard.buildHeader 0 5 1
A AddOptionFormCard.buildFooter 0 12 1
A AddOptionFormCard.create 0 6 1
1
import BaseCard from './BaseCard';
2
import {PollConfig} from '../helpers/interfaces';
3
import {chat_v1 as chatV1} from 'googleapis/build/src/apis/chat/v1';
4
5
export default class AddOptionFormCard extends BaseCard {
6
  private readonly config: PollConfig;
7
8
  constructor(config: PollConfig) {
9
    super();
10
    this.config = config;
11
  }
12
13
  create(): chatV1.Schema$GoogleAppsCardV1Card {
14
    this.buildHeader();
15
    this.buildSections();
16
    this.buildFooter();
17
    return this.card;
18
  }
19
20
  buildHeader() {
21
    this.card.header = {
22
      'title': 'Add a new option/choice',
23
      'subtitle': 'Q:' + this.config.topic,
24
    };
25
  }
26
27
  buildSections() {
28
    this.card.sections = [
29
      {
30
        'widgets': [
31
          {
32
            'textInput': {
33
              'label': 'Option Name',
34
              'type': 'SINGLE_LINE',
35
              'name': 'value',
36
              'hintText': '',
37
              'value': '',
38
            },
39
            'horizontalAlignment': 'START',
40
          },
41
        ],
42
      },
43
    ];
44
  }
45
46
  buildFooter() {
47
    this.card.fixedFooter = {
48
      'primaryButton': {
49
        'text': 'Add option',
50
        'onClick': {
51
          'action': {
52
            'function': 'add_option',
53
            'parameters': [
54
              {
55
                key: 'state',
56
                value: JSON.stringify(this.config),
57
              }],
58
          },
59
        },
60
      },
61
    };
62
  }
63
}
64