Skip to content
This repository was archived by the owner on Aug 27, 2018. It is now read-only.

Commit 0f695b1

Browse files
committed
Some fixes
1 parent 6e73a9f commit 0f695b1

File tree

11 files changed

+148
-80
lines changed

11 files changed

+148
-80
lines changed

3-panel/src/imports/materialdesign/components/TimePicker/components/MinutesClock/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default class MinutesClock extends Component {
4343
}
4444

4545
setTimeout(function () {
46-
timePicker.updateHour()
46+
timePicker.updateTime()
4747
}, 10)
4848
}
4949

3-panel/src/imports/materialdesign/components/TimePicker/index.js

Lines changed: 92 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ export default class TimePicker extends Component {
2525

2626
/**
2727
* Shows or hides time picker dialog.
28+
* @param {Boolean} set time to default (optional)
2829
*/
29-
toggle (flag) {
30+
toggle (flag, setTimeToDefault) {
3031
const root = this.getRoot()
3132

3233
root.style[(flag) ? 'display' : 'top'] = (flag) ? 'block' : '25%'
@@ -38,6 +39,7 @@ export default class TimePicker extends Component {
3839
}, (flag) ? 20 : 300)
3940

4041
this.toggleDark(flag)
42+
if (flag) this.reset(setTimeToDefault)
4143
}
4244

4345
/**
@@ -55,6 +57,60 @@ export default class TimePicker extends Component {
5557
}, (flag) ? 20 : 300)
5658
}
5759

60+
/**
61+
* Resets clocks.
62+
* @param {Boolean} set time to default (optional)
63+
*/
64+
reset (setTimeToDefault = true) {
65+
this.canSelectClock = true
66+
this.selectClock(true)
67+
68+
if (setTimeToDefault) {
69+
this.selectTime(true)
70+
this.setTime(6, 30)
71+
}
72+
}
73+
74+
/**
75+
* Sets time.
76+
* @param {Int} hour
77+
* @param {Int | String} minutes
78+
*/
79+
setTime (hour, minutes) {
80+
const hoursClock = this.elements.hoursClock
81+
const minutesClock = this.elements.minutesClock
82+
83+
const hoursTickIndex = this.getTickIndex(hoursClock, hour)
84+
const minutesTickIndex = this.getTickIndex(minutesClock, minutes)
85+
86+
if (hoursTickIndex < 0) console.log('cant find hour tick index')
87+
if (minutesTickIndex < 0) console.log('cant find minutes tick index')
88+
console.log(hoursTickIndex, minutesTickIndex)
89+
90+
const hoursTick = hoursClock.ticks[hoursTickIndex]
91+
const minutesTick = minutesClock.ticks[minutesTickIndex]
92+
93+
if (hoursClock.selectedTick !== hoursTick) this.selectTick(hoursTick, hoursClock)
94+
if (minutesClock.selectedTick !== minutesTick) this.selectTick(minutesTick, minutesClock)
95+
96+
this.updateTime()
97+
}
98+
99+
/**
100+
* Gets tick index.
101+
* @param {HoursClock | MinutesClock}
102+
* @param {Int | String} hour or minutes
103+
* @return {Int} tick index
104+
*/
105+
getTickIndex (clock, number) {
106+
for (var i = 0; i < clock.ticks.length; i++) {
107+
const tickNumber = clock.ticks[i].props.number
108+
if (tickNumber == number) return i
109+
}
110+
111+
return -1
112+
}
113+
58114
/**
59115
* Enables selecting hour or minute.
60116
*/
@@ -72,14 +128,14 @@ export default class TimePicker extends Component {
72128
window.removeEventListener('mouseup', this.disableSelecting)
73129

74130
if (this.actualClock === this.elements.hoursClock) {
75-
this.selectClock(this.elements.minutesClock)
131+
this.selectClock(false)
76132
}
77133
}
78134

79135
/**
80-
* Updates hour.
136+
* Updates time.
81137
*/
82-
updateHour () {
138+
updateTime () {
83139
const hoursClock = this.elements.hoursClock
84140
const minutesClock = this.elements.minutesClock
85141

@@ -91,23 +147,23 @@ export default class TimePicker extends Component {
91147

92148
/**
93149
* Selects clock.
94-
* @param {HoursClock | MinutesClock}
150+
* @param {Boolean} select hours clock
95151
*/
96-
selectClock (clock) {
97-
if (this.actualClock !== clock && this.canSelectClock) {
98-
this.actualClock = clock
152+
selectClock (selectHoursClock) {
153+
const hoursClock = this.elements.hoursClock
154+
const minutesClock = this.elements.minutesClock
99155

100-
const hoursClock = this.elements.hoursClock
101-
const minutesClock = this.elements.minutesClock
156+
const clock = (selectHoursClock) ? hoursClock : minutesClock
102157

103-
const isMinutesClock = (clock === this.elements.minutesClock)
158+
if (this.actualClock !== clock && this.canSelectClock) {
159+
this.actualClock = clock
104160

105-
this.toggleClock(false, (isMinutesClock) ? hoursClock : minutesClock)
161+
this.toggleClock(false, (selectHoursClock) ? minutesClock : hoursClock)
106162
this.canSelectClock = false
107163

108164
const self = this
109165
setTimeout(function () {
110-
self.toggleClock(true, (isMinutesClock) ? minutesClock : hoursClock)
166+
self.toggleClock(true, (selectHoursClock) ? hoursClock : minutesClock)
111167

112168
setTimeout(function () {
113169
self.canSelectClock = true
@@ -117,8 +173,8 @@ export default class TimePicker extends Component {
117173
const hourDisplay = this.elements.hour
118174
const minutesDisplay = this.elements.minutes
119175

120-
this.select(false, (isMinutesClock ? hourDisplay : minutesDisplay))
121-
this.select(true, (isMinutesClock ? minutesDisplay : hourDisplay))
176+
this.select(false, (selectHoursClock ? minutesDisplay : hourDisplay))
177+
this.select(true, (selectHoursClock ? hourDisplay : minutesDisplay))
122178
}
123179
}
124180

@@ -157,24 +213,24 @@ export default class TimePicker extends Component {
157213

158214
/**
159215
* Selects time. (AM, PM)
160-
* @param {DOMElement}
216+
* @param {Boolean} select AM
161217
*/
162-
selectTime (element) {
218+
selectTime (selectAM) {
163219
const am = this.elements.am
164220
const pm = this.elements.pm
165221

166-
this.isAM = (element === am)
222+
this.select(false, (selectAM) ? pm : am)
223+
this.select(true, (selectAM) ? am : pm)
167224

168-
this.select(false, (this.isAM) ? pm : am)
169-
this.select(true, (this.isAM) ? am : pm)
225+
this.isAM = selectAM
170226
}
171227

172228
/**
173229
* Calculates ticks position.
174-
* @param {Int} circle radius (Optional)
175-
* @param {Int} circle size (Optional)
176-
* @param {Int} tick size (Optional)
177-
* @param {Int} ticks count (Optional)
230+
* @param {Int} circle radius (optional)
231+
* @param {Int} circle size (optional)
232+
* @param {Int} tick size (optional)
233+
* @param {Int} ticks count (optional)
178234
* @return {Object} positions
179235
*/
180236
calculateTickPosition (radius = 108, size = 270, tickSize = 40, length = 12) {
@@ -197,18 +253,19 @@ export default class TimePicker extends Component {
197253
/**
198254
* Selects tick.
199255
* @param {Tick}
256+
* @param {HoursClock | MinutesClock} clock (optional)
200257
*/
201-
selectTick (tick) {
202-
const line = this.actualClock.elements.line
203-
const rotate = this.actualClock.getRotate(tick.props.number)
258+
selectTick (tick, clock = this.actualClock) {
259+
const line = clock.elements.line
260+
const rotate = clock.getRotate(tick.props.number)
204261

205262
line.style.transform = 'translateY(-75%) rotate(' + rotate + 'deg)'
206263

207264
tick.getRoot().classList.add('selected')
208265

209-
this.deselectTick(this.actualClock.selectedTick)
210-
this.actualClock.selectedTick = tick
211-
this.updateHour()
266+
this.deselectTick(clock.selectedTick)
267+
clock.selectedTick = tick
268+
this.updateTime()
212269
}
213270

214271
/**
@@ -245,20 +302,20 @@ export default class TimePicker extends Component {
245302
<div className='material-time-picker' ref='root'>
246303
<div className='date-display'>
247304
<div className='date-container'>
248-
<span className='hour selected' ref='hour' onClick={() => this.selectClock(this.elements.hoursClock)}>
305+
<span className='hour selected' ref='hour' onClick={() => this.selectClock(true)}>
249306
6
250307
</span>
251308
<span className='separate'>
252309
:
253310
</span>
254-
<span className='minutes' ref='minutes' onClick={() => this.selectClock(this.elements.minutesClock)}>
311+
<span className='minutes' ref='minutes' onClick={() => this.selectClock(false)}>
255312
30
256313
</span>
257314
<div className='am-pm-container'>
258-
<div className='item selected' ref='am' onClick={() => this.selectTime(this.elements.am)}>
315+
<div className='item selected' ref='am' onClick={() => this.selectTime(true)}>
259316
AM
260317
</div>
261-
<div className='item' ref='pm' onClick={() => this.selectTime(this.elements.pm)}>
318+
<div className='item' ref='pm' onClick={() => this.selectTime(false)}>
262319
PM
263320
</div>
264321
</div>
@@ -284,13 +341,11 @@ export default class TimePicker extends Component {
284341
if (props.darkOpacity == null) props.darkOpacity = 0.7
285342
if (props.actionButtonRippleStyle == null) {
286343
props.actionButtonRippleStyle = {
287-
backgroundColor: '#26a69a',
344+
backgroundColor: '#3f51b5',
288345
opacity: 0.3
289346
}
290347
}
291348

292-
this.toggle(true)
293-
294349
this.actualClock = this.elements.hoursClock
295350

296351
const buttons = (

3-panel/src/imports/materialdesign/components/TimePicker/style.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
& .date-display {
1717
width: 196px;
1818
height: 100%;
19-
background-color: #26a69a;
19+
background-color: #3f51b5;
2020
position: absolute;
2121
left: 0;
2222
top: 0;
@@ -84,7 +84,7 @@
8484
background-color: #eee;
8585

8686
& .dot {
87-
background-color: #26a69a;
87+
background-color: #3f51b5;
8888
width: 8px;
8989
height: 8px;
9090
border-radius: 100%;
@@ -93,7 +93,7 @@
9393
}
9494

9595
& .line {
96-
background-color: #26a69a;
96+
background-color: #3f51b5;
9797
height: calc(50% - 28px);
9898
width: 2px;
9999
position: absolute;
@@ -121,7 +121,7 @@
121121
}
122122

123123
&.selected {
124-
background-color: #26a69a;
124+
background-color: #3f51b5;
125125
color: #fff;
126126
}
127127
}
@@ -146,7 +146,7 @@
146146
float: right;
147147
margin-right: 8px;
148148
background-color: transparent;
149-
color: #26a69a;
149+
color: #3f51b5;
150150
min-width: 0px;
151151
padding-left: 18px;
152152
padding-right: 18px;

3-panel/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import App from './views/test'
1+
import App from './views/App'
22
import UI from './helpers/UI'
33

44
import './styles.scss'

3-panel/src/views/App/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import Menu from './../../imports/materialdesign/components/Menu'
3030
import Preloader from './../../imports/materialdesign/components/Preloader'
3131
import Snackbar from './../../imports/materialdesign/components/Snackbar'
3232
import Tooltip from './../../imports/materialdesign/components/Tooltip'
33+
import TimePicker from './../../imports/materialdesign/components/TimePicker'
3334

3435
export default class App extends Component {
3536
beforeRender () {
@@ -427,6 +428,7 @@ export default class App extends Component {
427428
<DeletePicturesDialog ref='deletePicturesDialog' />
428429
<AddLessonDialog ref='addLessonDialog' />
429430
<ErrorDialog ref='errorDialog' />
431+
<TimePicker ref='timePicker' onConfirm={(hour, minutes, isAM) => { this.getLessonsPlanPage().onTimePickerConfirm(hour, minutes, isAM) }} />
430432
<Snackbar ref='deletePostsSnackbar' text='Pomyślnie usunięto posty' />
431433
<Snackbar ref='deletePostSnackbar' text='Pomyślnie usunięto post' />
432434
<Snackbar ref='addPostSnackbar' text='Pomyślnie dodano post' />

3-panel/src/views/Pages/LessonsPlan/components/Day/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ export default class Day extends Component {
110110
* @param {Event}
111111
*/
112112
onWindowMouseUp = (e) => {
113-
console.log('window mouse up event')
114113
this.toggleMovingMode(false)
115114
}
116115

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import Component from '../../../../../../../helpers/Component'
22

3-
import TextField from '../../../../../../../imports/materialdesign/components/TextField'
4-
53
export default class Item extends Component {
6-
74
/**
85
* Gets root.
96
* @return {DOMElement} root
@@ -12,16 +9,41 @@ export default class Item extends Component {
129
return this.elements.root
1310
}
1411

12+
editStart = (e) => {
13+
const app = window.app
14+
const timePicker = app.elements.timePicker
15+
16+
const time = this.props.start
17+
const split = time.split('.')
18+
let hour = split[0]
19+
const minutes = split[1]
20+
21+
if (hour > 12) {
22+
hour -= 12
23+
timePicker.selectTime(false)
24+
} else if (!timePicker.isAM) {
25+
timePicker.selectTime(true)
26+
}
27+
28+
timePicker.setTime(hour, minutes)
29+
timePicker.toggle(true, false)
30+
}
31+
1532
render () {
1633
return (
1734
<div className='item'>
18-
<TextField ref='start' type='datetime' />
19-
<TextField ref='finish' type='number' />
35+
<div className='start' ref='start' onClick={this.editStart} />
36+
<div className='finish' ref='finish' />
2037
</div>
2138
)
2239
}
2340

2441
afterRender () {
25-
this.props.getLessonHours().items.push(this)
42+
const props = this.props
43+
44+
props.getLessonHours().items.push(this)
45+
46+
this.elements.start.innerHTML = props.start
47+
this.elements.finish.innerHTML = props.finish
2648
}
2749
}

3-panel/src/views/Pages/LessonsPlan/components/LessonHours/index.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ export default class Day extends Component {
2525
for (var i = 0; i < lessonsPlanPage.lessonsStart.length; i++) {
2626
this.addItem(lessonsPlanPage.lessonsStart[i], lessonsPlanPage.lessonsFinish[i])
2727
}
28-
29-
for (var i = 0; i < this.items.length; i++) {
30-
const item = this.items[i]
31-
32-
item.elements.start.setValue(lessonsPlanPage.lessonsStart[i], false)
33-
item.elements.finish.setValue(lessonsPlanPage.lessonsFinish[i], false)
34-
}
3528
}
3629

3730
addItem (start, finish) {

0 commit comments

Comments
 (0)