1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
import * as React from 'react';
import './CalendarManager.scss';
import { observer } from "mobx-react";
import { action, computed, observable, runInAction } from 'mobx';
import { Doc } from '../../fields/Doc';
import { DocumentView } from '../views/nodes/DocumentView';
import { DictationOverlay } from '../views/DictationOverlay';
import { TaskCompletionBox } from '../views/nodes/TaskCompletedBox';
import { MainViewModal } from '../views/MainViewModal';
import { TextField } from '@material-ui/core';
import Select from 'react-select';
import { SettingsManager } from './SettingsManager';
import { StrCast } from '../../fields/Types';
import { SelectionManager } from './SelectionManager';
import { DocumentManager } from './DocumentManager';
import { DocData } from '../../fields/DocSymbols';
import { DateRange, Range, RangeKeyDict } from 'react-date-range';
import { Button } from 'browndash-components';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { IconLookup, faPlus } from '@fortawesome/free-solid-svg-icons';
import 'react-date-range/dist/styles.css';
import 'react-date-range/dist/theme/default.css';
type CreationType = 'new-calendar' | 'existing-calendar' | 'manage-calendars';
@observer
export class CalendarManager extends React.Component<{}> {
public static Instance: CalendarManager;
@observable private isOpen = false;
@observable private targetDoc: Doc | undefined; // the target document
@observable private targetDocView: DocumentView | undefined; // the DocumentView of the target doc
@observable private dialogueBoxOpacity = 1; // for the modal
@observable private overlayOpacity = 0.4; // for the modal
@observable private layoutDocAcls: boolean = false; // whether the layout doc or data doc's acls are to be used
@observable private creationType: CreationType = 'new-calendar';
@observable
calendarName: string = "";
@action
setInterationType = (type: CreationType) => {
this.creationType = type;
}
public open = (target?: DocumentView, target_doc?: Doc) => {
console.log('hi');
runInAction(() => {
this.targetDoc = target_doc || target?.props.Document;
this.targetDocView = target;
DictationOverlay.Instance.hasActiveModal = true;
this.isOpen = this.targetDoc !== undefined;
})
};
public close = action(() => {
this.isOpen = false;
TaskCompletionBox.taskCompleted = false;
setTimeout(
action(() => {
DictationOverlay.Instance.hasActiveModal = false;
this.targetDoc = undefined;
}), 500
);
this.layoutDocAcls = false;
});
constructor(props: {}) {
super(props);
CalendarManager.Instance = this;
}
componentDidMount(): void {
}
private focusOn = (contents: string) => {
const title = this.targetDoc ? StrCast(this.targetDoc.title) : '';
const docs = SelectionManager.Views().length > 1 ? SelectionManager.Views().map(docView => docView.props.Document) : [this.targetDoc];
return (
<span
className="focus-span"
title={title}
onClick={() => {
if (this.targetDoc && this.targetDocView && docs.length === 1) {
DocumentManager.Instance.showDocument(this.targetDoc, { willZoomCentered: true });
}
}}
onPointerEnter={action(() => {
if (docs.length) {
docs.forEach(doc => doc && Doc.BrushDoc(doc));
this.dialogueBoxOpacity = 0.1;
this.overlayOpacity = 0.1;
}
})}
onPointerLeave={action(() => {
if (docs.length) {
docs.forEach(doc => doc && Doc.UnBrushDoc(doc));
this.dialogueBoxOpacity = 1;
this.overlayOpacity = 0.4;
}
})}>
{contents}
</span>
);
};
@observable
selectedDateRange: Range[] = [{
startDate: new Date(),
endDate: undefined,
key: 'selection'
}]
@action
setSelectedDateRange = (range: Range[]) => {
this.selectedDateRange = range;
}
@computed
get createButtonActive() {
if (this.calendarName.length === 0) return false // disabled if no calendar name
let startDate: Date | undefined;
let endDate: Date | undefined;
try {
startDate = this.selectedDateRange[0].startDate;
endDate = this.selectedDateRange[0].endDate;
} catch (e: any){
return false; // disabled
}
if (!startDate || !endDate) return false; // disabled if any is undefined
return true;
}
@computed
get calendarInterface(){
let docs = SelectionManager.Views().length < 2 ? [this.targetDoc] : SelectionManager.Views().map(docView => docView.rootDoc);
const targetDoc = this.layoutDocAcls ? docs[0] : docs[0]?.[DocData];
const currentDate = new Date();
return (
<div
className='calendar-interface'
style= {{
background: SettingsManager.userBackgroundColor,
color: StrCast(Doc.UserDoc().userColor)
}}
>
<p className="selected-doc-title" style={{ color: SettingsManager.userColor }}>
<b>{this.focusOn(docs.length < 2 ? StrCast(targetDoc?.title, 'this document') : '-multiple-')}</b>
</p>
<div className='creation-type-container'>
<div
className={`calendar-creation ${this.creationType === 'new-calendar' ? 'calendar-creation-selected' : ''}`}
onClick={(e) => this.setInterationType('new-calendar')}
>
Add to New Calendar
</div>
<div
className={`calendar-creation ${this.creationType === 'existing-calendar' ? 'calendar-creation-selected' : ''}`}
onClick={(e) => this.setInterationType('existing-calendar')}
>
Add to Existing calendar
</div>
</div>
<div className='choose-calendar-container'>
{this.creationType === 'new-calendar' ?
<TextField
fullWidth
placeholder='Enter calendar name...'
variant='filled'
style={{
backgroundColor: 'white',
color: 'black',
borderRadius: '5px'
}}
/>
:
<Select
className='existing-calendar-search'
placeholder='Search for existing calendar...'
isMulti
isSearchable
>
</Select>
}
</div>
<div className='date-range-picker-container'>
<DateRange
className='react-date-range'
editableDateInputs={true}
// ranges={[selectionRange]}
onChange={item => this.setSelectedDateRange([item.selection])}
ranges={this.selectedDateRange}
// onChange={this.handleSelect}
/>
</div>
<div className='create-button-container'>
<Button
active={this.createButtonActive}
text="Add to Calendar"
iconPlacement='right'
icon={<FontAwesomeIcon icon={faPlus as IconLookup}/>}
/>
</div>
</div>
)
}
render() {
return (
<MainViewModal
contents={this.calendarInterface}
isDisplayed={this.isOpen}
interactive={true}
dialogueBoxDisplayedOpacity={this.dialogueBoxOpacity}
overlayDisplayedOpacity={this.overlayOpacity}
closeOnExternalClick={this.close}
/>
)
}
}
|