Skip to content

Commit

Permalink
handle new school years using externalService courses
Browse files Browse the repository at this point in the history
Email is temp disabled, since I don't really know if all this stuff works
cleanly.
  • Loading branch information
lieuwex committed Jan 20, 2017
1 parent 9f1c274 commit 8727cd2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 63 deletions.
10 changes: 0 additions & 10 deletions client/app/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ class @App
NotificationsManager.hideAll()

# == Modals ==
Template.newSchoolYearModal.helpers classes: -> classes()

Template.newSchoolYearModal.events
"change": (event) ->
target = $(event.target)
checked = target.is ":checked"
classId = target.attr "classid"

target.find("span").css color: if checked then "lightred" else "white"

Template.addTicketModal.helpers
body: -> Session.get('addTicketModalContent') ? ''

Expand Down
29 changes: 0 additions & 29 deletions client/app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,6 @@ <h4 class="modal-title">Vakken</h4>
</div>
</template>

<template name="newSchoolYearModal">
<div class="modal fade" aria-hidden="true" id="newSchoolYearModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Nieuw Schooljaar</h4>
</div>
<div class="modal-body">
<h4 style="text-align: center; margin-bottom: 20px;">Welken vakken moeten er weg?<small><br>Vakken kan je zometeen toevoegen.</small></h4>
{{#each classes}}
<div class="classRemoveRow">
<label>
<input type="checkbox" classId="{{_id._str}}">
<span id="checkboxLabel">
{{name}}
</span>
</label>
</div>
{{/each}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="goButton">Okido</button>
</div>
</div>
</div>
</div>
</template>

<template name="addTicketModal">
<div class="modal fade" aria-hidden="true" id="addTicketModal">
<div class="modal-dialog">
Expand Down
29 changes: 5 additions & 24 deletions client/app/setup/setup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ setupItems = [
name: 'externalServices'
async: no
onDone: (cb) ->
# well, this externalServices global shit stuff is a fucking mess.

schoolId = _(externalServices.get())
.map (s) -> s.profileData()?.schoolId
.find _.negate _.isUndefined

schoolId ?= getUserField Meteor.userId(), 'profile.schoolId'

done = (success) ->
if success?
addProgress 'externalServices', -> cb yes
Expand Down Expand Up @@ -193,26 +197,7 @@ setupItems = [
}

{
# TODO: implement this, it should open a modal that asks
# if the current schoolyear is over, if so we can ask the user to follow the setup
# with stuff as `externalServices` and `externalClasses` again.
name: 'newSchoolYear'
func: ->
return undefined

alertModal(
"Hey!",
Locals["nl-NL"].NewSchoolYear(),
DialogButtons.Ok,
{ main: "verder" },
{ main: "btn-primary" },
{ main: (->) },
no
)
}

{
name: 'first-use'
name: 'final'
func: ->
addProgress 'first-use', ->
name = getUserField Meteor.userId(), 'profile.firstName'
Expand All @@ -231,10 +216,6 @@ running = undefined
setupProgress = getUserField Meteor.userId(), 'setupProgress'
return undefined unless setupProgress?

setupProgress = setupProgress.concat [
'newSchoolYear' # TODO: Dunno how're going to do this shit
]

running = _.filter setupItems, (item) -> item.name not in setupProgress

if running.length > 0
Expand Down
44 changes: 44 additions & 0 deletions server/cronJobs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,47 @@ SyncedCron.add
Date.today()
Date.today().addDays 14
)

SyncedCron.add
name: 'Handle new schoolyears'
schedule: (parser) -> parser.recur().on(4).hour()
job: ->
userIds = Meteor.users.find({
'profile.firstName': $ne: ''
}, {
fields:
_id: 1
'profile.firstName': 1
emails: 1
}).map (u) -> u._id

for userId in userIds
courses = functions.getCourses userId
current = _.find courses, (c) -> c.inside new Date
next = _.find courses, (c) -> c.from > new Date

if current? and Date.today().addDays(-1) < current.start
###
loginUrl = 'https://app.simplyHomework.nl/login'
sendMail user, 'Nieuw schooljaar', """
Hey #{user.profile.firstName}!
Zo te zien is het nieuwe schooljaar zojuist voor je begonnen.
We hopen dat simplyHomework je dit jaar weer kan helpen met school! :)
Je moet wel even eerst de setup doorlopen (ongeveer 2 minuten) op: <a href='#{loginurl}'>#{loginurl}</a>
Success dit schooljaar!
"""
###
Meteor.users.update(
userId
$pullAll: setupProgress: [
'externalServices'
'extractInfo'
'getExternalClasses'
]
)

# REVIEW: do we want to send a message here? If so, what?
# else unless next?

0 comments on commit 8727cd2

Please sign in to comment.