Skip to content

Commit

Permalink
Merge pull request #1 from HackAssistant/master
Browse files Browse the repository at this point in the history
Update from HA
  • Loading branch information
AsLogd authored Oct 16, 2018
2 parents f5c416a + f7165ae commit 3c2fc2f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
1 change: 1 addition & 0 deletions hardware/static/js/hw.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ let hw = (()=>{
let msg = msg_in || ""
let title = title_in || "HackathonAssistant"
let closeIn = time || 10000
var icon = icon || window.location.origin + "/static/favicon.png"
let notification = new Notification(title, {
body: msg,
icon: icon
Expand Down
73 changes: 44 additions & 29 deletions hardware/static/js/hw_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let hw_list = ((hw)=>{
element.innerHTML=count
}
function notifyAvailableItem(item){
hw.notify("A "+item.name+" has become available! Click the notification to request.",
hw.notify("A "+item.name+" has become available! Click the notification to request (May not work in your browser).",
"HackathonAssistant", "", ()=>{
hw.ajax_req({
'req_item':true,
Expand Down Expand Up @@ -71,52 +71,67 @@ let hw_list = ((hw)=>{
checkItems.push(itemId)
if(!timer){
timer = setInterval(()=>{
if(!checkItems)
timer = false
hw.ajax_req({
'check_availability': true,
'item_ids': checkItems
}, (data)=>{
for(let item of data.available_items){
obj.stopPool(item.id)
notifyAvailableItem(item)
var btn =$("[data-item-id="+item.id+"]")[0]
btn.dataset.action = 'request'
btn.innerHTML = "REQUEST"
btn.classList.remove('active')
}
if(!checkItems.length)
{
clearInterval(timer)
timer = false
}
})
}, POOLING_TIME)
}
}
obj.initListeners = ()=>{
$("[data-action='lmk']").on("click", (ev)=>{
if($(ev.target).hasClass('active')){
$(ev.target).removeClass('active')
obj.stopPool(ev.target.dataset.itemId)
return
$("[data-action]").on("click", (ev)=>{
if(ev.currentTarget.dataset.action === 'lmk')
{
if($(ev.target).hasClass('active'))
{
$(ev.target).removeClass('active')
obj.stopPool(ev.target.dataset.itemId)
return
}
if(!hw.canNotify)
{
hw.initNotifications((permission)=>{
if(permission){
hw.notify("Notifications enabled!")
$(ev.target).addClass('active')
obj.poolAvailability(ev.target.dataset.itemId)
}
})
}
else
{
$(ev.target).addClass('active')
obj.poolAvailability(ev.target.dataset.itemId)
}
}
if(!hw.canNotify){
hw.initNotifications((permission)=>{
if(permission){
hw.notify("Notifications enabled!")
$(ev.target).addClass('active')
obj.poolAvailability(ev.target.dataset.itemId)
else
{
hw.ajax_req({
'req_item':true,
'item_id': ev.currentTarget.dataset.itemId,
}, (data)=>{
if(data.ok){
ev.currentTarget.dataset.targetTime = "00:"+data.minutes+":00"
obj.setTimer(ev.currentTarget)
}
})
} else {
$(ev.target).addClass('active')
obj.poolAvailability(ev.target.dataset.itemId)
})
}

})
$("[data-action='request']").on("click", (ev)=>{
hw.ajax_req({
'req_item':true,
'item_id': ev.currentTarget.dataset.itemId,
}, (data)=>{
if(data.ok){
ev.currentTarget.dataset.targetTime = "00:"+data.minutes+":00"
obj.setTimer(ev.currentTarget)
}
})
})
$(".hw-toggle").on("click", (ev)=>{
$(ev.currentTarget).toggleClass("open")
$(ev.currentTarget).siblings(".hw-toggle-actor").toggleClass("open")
Expand Down
8 changes: 8 additions & 0 deletions hardware/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class HardwareBorrowingsView(TabsViewMixin, SingleTableMixin, FilterView):
table_pagination = {'per_page': 50}
filterset_class = BorrowingFilter

def get_context_data(self, **kwargs):
context = super(HardwareBorrowingsView, self).get_context_data(**kwargs)
if not self.request.user.is_hardware_admin:
context['filter'] = False
context['table'].exclude = ('id', 'user', 'lending_by', 'return_by')

return context

def get_current_tabs(self):
return hardware_tabs(self.request.user)

Expand Down

0 comments on commit 3c2fc2f

Please sign in to comment.