src/cards/ScheduleClosePollFormCard.ts   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 1.75

Size

Lines of Code 76
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 57
mnd 3
bc 3
fnc 4
dl 0
loc 76
rs 10
bpm 0.75
cpm 1.75
noi 0
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A ScheduleClosePollFormCard.create 0 9 2
A ScheduleClosePollFormCard.buildButtons 0 10 2
A ScheduleClosePollFormCard.buildAutoCloseSection 0 34 2
A ScheduleClosePollFormCard.buildHeader 0 7 1
1
import {chat_v1 as chatV1} from '@googleapis/chat';
2
import {offsetToTimezone} from '../helpers/time';
3
import ClosePollFormCard from './ClosePollFormCard';
4
import {createButton} from '../helpers/cards';
5
6
export default class ScheduleClosePollFormCard extends ClosePollFormCard {
7
  create(): chatV1.Schema$GoogleAppsCardV1Card {
8
    this.buildHeader();
9
    if (this.state.closedTime) {
10
      this.buildCurrentScheduleInfo();
11
    }
12
    this.buildAutoCloseSection();
13
    this.buildButtons();
14
    this.buildSections();
15
    return this.card;
16
  }
17
18
  buildHeader() {
19
    this.card.header = {
20
      'title': 'Schedule Close Poll',
21
      'subtitle': 'You can schedule the poll to close here.',
22
      'imageUrl': '',
23
      'imageType': 'CIRCLE',
24
    };
25
  }
26
27
  buildButtons() {
28
    let scheduleButtonText = 'Create Schedule Close';
29
    if (this.state.closedTime) {
30
      scheduleButtonText = 'Edit Schedule Close';
31
    }
32
33
    this.addSectionWidget({
34
      'buttonList': {
35
        'buttons': [createButton(scheduleButtonText, 'schedule_close_poll')],
36
      },
37
    });
38
  }
39
40
  buildAutoCloseSection() {
41
    const widgets: chatV1.Schema$GoogleAppsCardV1Widget[] = [];
42
    const timezone = offsetToTimezone(this.timezone.offset);
43
    let scheduleTime = Date.now() + 18000000;
44
    if (this.state.closedTime) {
45
      scheduleTime = this.state.closedTime;
46
    }
47
    scheduleTime += this.timezone.offset;
48
    widgets.push(
49
      {
50
        'dateTimePicker': {
51
          'label': 'Close schedule time ' + timezone,
52
          'name': 'close_schedule_time',
53
          'type': 'DATE_AND_TIME',
54
          'valueMsEpoch': scheduleTime.toString(),
55
        },
56
      });
57
58
    widgets.push(
59
      {
60
        'decoratedText': {
61
          'text': 'Auto mention <b>@all</b> on 5 minutes before poll closed',
62
          'bottomLabel': 'This is to ensure that other users do not forget to vote before the poll is closed.',
63
          'switchControl': {
64
            'controlType': 'SWITCH',
65
            'name': 'auto_mention',
66
            'value': '1',
67
            'selected': true,
68
          },
69
        },
70
      });
71
    this.card.sections!.push({
72
      widgets,
73
    });
74
  }
75
}
76