forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDashboardOptionsMenu.js
More file actions
184 lines (164 loc) · 5.85 KB
/
Copy pathDashboardOptionsMenu.js
File metadata and controls
184 lines (164 loc) · 5.85 KB
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
/*
* Copyright (C) 2016 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React from 'react'
import PropTypes from 'prop-types'
import I18n from 'i18n!dashboard'
import axios from 'axios'
import ScreenReaderContent from 'instructure-ui/lib/components/ScreenReaderContent'
import PopoverMenu from 'instructure-ui/lib/components/PopoverMenu'
import { MenuItem, MenuItemGroup, MenuItemSeparator } from 'instructure-ui/lib/components/Menu'
import Button from 'instructure-ui/lib/components/Button'
import IconSettings2Solid from 'instructure-icons/react/Solid/IconSettings2Solid'
export default class DashboardOptionsMenu extends React.Component {
static propTypes = {
recent_activity_dashboard: PropTypes.bool.isRequired,
hide_dashcard_color_overlays: PropTypes.bool,
planner_enabled: PropTypes.bool,
planner_selected: PropTypes.bool
}
static defaultProps = {
hide_dashcard_color_overlays: false,
planner_enabled: false,
planner_selected: false
}
constructor (props) {
super(props)
let view;
if (props.planner_enabled && props.planner_selected) {
view = ['planner']
} else if (props.recent_activity_dashboard) {
view = ['activity']
} else {
view = ['cards']
}
this.state = {
view,
colorOverlays: props.hide_dashcard_color_overlays ? [] : ['colorOverlays']
}
}
handleViewOptionSelect = (e, newSelected) => {
if (newSelected.length === 0) {
return
}
this.setState({view: newSelected}, () => {
this.toggleDashboardView(this.state.view)
this.postDashboardToggle()
})
}
handleColorOverlayOptionSelect = (e, newSelected) => {
this.setState({
colorOverlays: newSelected
}, this.toggleColorOverlays)
this.postToggleColorOverlays()
}
toggleDashboardView (newView) {
const fakeObj = {
style: {}
}
const dashboardPlanner = document.getElementById('dashboard-planner') || fakeObj
const dashboardPlannerHeader = document.getElementById('dashboard-planner-header') || fakeObj
const dashboardActivity = document.getElementById('dashboard-activity')
const dashboardCards = document.getElementById('DashboardCard_Container')
if (newView[0] === 'planner') {
dashboardPlanner.style.display = 'block'
dashboardPlannerHeader.style.display = 'block'
dashboardActivity.style.display = 'none'
dashboardCards.style.display = 'none'
} else if (newView[0] === 'activity') {
dashboardPlanner.style.display = 'none'
dashboardPlannerHeader.style.display = 'none'
dashboardActivity.style.display = 'block'
dashboardCards.style.display = 'none'
} else {
dashboardPlanner.style.display = 'none'
dashboardPlannerHeader.style.display = 'none'
dashboardActivity.style.display = 'none'
dashboardCards.style.display = 'block'
}
}
toggleColorOverlays () {
const dashcardHeaders = Array.from(document.getElementsByClassName('ic-DashboardCard__header'))
dashcardHeaders.forEach((dashcardHeader) => {
const dashcardImageHeader = dashcardHeader.getElementsByClassName('ic-DashboardCard__header_image')[0]
if (dashcardImageHeader) {
const dashcardOverlay = dashcardImageHeader.getElementsByClassName('ic-DashboardCard__header_hero')[0]
dashcardOverlay.style.opacity = this.colorOverlays ? 0.6 : 0
const headerButtonBg = dashcardHeader.getElementsByClassName('ic-DashboardCard__header-button-bg')[0]
headerButtonBg.style.opacity = this.colorOverlays ? 0 : 1
}
})
}
postDashboardToggle () {
axios.put('/dashboard/view', {
dashboard_view: this.state.view[0]
})
}
postToggleColorOverlays () {
axios.post('/users/toggle_hide_dashcard_color_overlays');
}
get cardView () {
return this.state.view.includes('cards')
}
get colorOverlays () {
return this.state.colorOverlays.includes('colorOverlays')
}
render () {
const cardView = this.cardView
return (
<PopoverMenu
trigger={
<Button variant="icon">
<ScreenReaderContent>{I18n.t('Dashboard Options')}</ScreenReaderContent>
<IconSettings2Solid />
</Button>
}
contentRef={(el) => { this.menuContentRef = el; }}
>
<MenuItemGroup
label={I18n.t('Dashboard View')}
onSelect={this.handleViewOptionSelect}
selected={this.state.view}
>
<MenuItem value="cards">{I18n.t('Card View')}</MenuItem>
{
(this.props.planner_enabled) && (
<MenuItem value="planner">{I18n.t('List View')}</MenuItem>
)
}
<MenuItem value="activity">{I18n.t('Recent Activity')}</MenuItem>
</MenuItemGroup>
{ cardView && <MenuItemSeparator /> }
{ cardView && (
<MenuItemGroup
label={
<ScreenReaderContent>
{I18n.t('Toggle course card color overlays')}
</ScreenReaderContent>
}
onSelect={this.handleColorOverlayOptionSelect}
selected={this.state.colorOverlays}
>
<MenuItem value="colorOverlays">
{ I18n.t('Color Overlay') }
</MenuItem>
</MenuItemGroup>
)}
</PopoverMenu>
)
}
}