Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
rodfersou committed Sep 24, 2018
1 parent b55e0e8 commit e19dd36
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
5 changes: 1 addition & 4 deletions src/brasil/gov/agenda/browser/agenda.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def setup(self):
self._ts = api.portal.get_tool('translation_service')
self.agenda = self.context
self.editable = context_state.is_editable()
self.date = datetime.now()

def results(self, b_size=16):
"""Retorna as ultimas agendas diárias"""
Expand All @@ -45,10 +46,6 @@ def results(self, b_size=16):
results = Batch(results, b_size, b_start)
return results

@property
def date(self):
return datetime.now()

def __call__(self):
self.setup()
agenda_recente = self.agenda_recente()
Expand Down
13 changes: 6 additions & 7 deletions src/brasil/gov/agenda/browser/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,28 @@ def _translate(self, msgid, locale='plonelocales', mapping=None):

def month(self):
tool = api.portal.get_tool('translation_service')
date = self.date
strmonth = self._translate(tool.month_msgid(date.strftime('%m')))
strmonth = self._translate(tool.month_msgid(self.date.strftime('%m')))
return {
'strmonth': strmonth[:3].upper(),
'strmonthcomplete': strmonth.upper(),
'month': date.month,
'year': date.year,
'month': self.date.month,
'year': self.date.year,
}

def days(self):
tool = api.portal.get_tool('translation_service')
date = self.date
# get a list with 3 days before and 3 days after current day
days = [(date + timedelta(i)) for i in range(-3, 4)]
days = [(self.date + timedelta(i)) for i in range(-3, 4)]
weekdays = []
for day in days:
cssclass = ['day']
has_appointment = False
if day == date:
if day == self.date:
cssclass.append('is-selected')
if self.agenda.get(day.strftime('%Y-%m-%d'), False):
has_appointment = True
cssclass.append('has-appointment')
# Weekday difference between datetime and DateTime objects
strweek = self._translate(tool.day_msgid((day.weekday() + 1) % 7))
weekdays.append({
'day': day.day,
Expand Down
11 changes: 7 additions & 4 deletions src/brasil/gov/agenda/tiles/agenda.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ class AgendaTile(PersistentCoverTile, AgendaMixin):
limit = 1
page_size = 3 # items by swiper slide

def __init__(self, context, request):
super(AgendaTile, self).__init__(context, request)
self.setup()

def setup(self):
self.date = datetime.now()

def populate_with_object(self, obj):
super(AgendaTile, self).populate_with_object(obj) # check permissions

Expand Down Expand Up @@ -179,10 +186,6 @@ def results(self):
data = data_mgr.get()
return data

@property
def date(self):
return datetime.now()

def is_empty(self):
data = self.results()
return data['title'] is None
Expand Down
6 changes: 6 additions & 0 deletions webpack/app/js/agenda.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export default class AgendaView {
$(selector) {
return $(selector, this.container.parentElement);
}
/**
* Create overlays
* Create overlays when edit and remove appointments
**/
bindEvents(){
// overlay when edit appointment
this.$('.editar_compromisso').prepOverlay({
subtype: 'ajax',
filter: common_content_filter,
Expand All @@ -25,6 +30,7 @@ export default class AgendaView {
closeselector: '[name="form.buttons.cancel"]',
width:'50%'
});
// overlay when delete appointment
this.$('.remover_compromisso').prepOverlay({
subtype: 'ajax',
filter: common_content_filter,
Expand Down
8 changes: 8 additions & 0 deletions webpack/app/js/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export default class AgendaTile {
},
});
}
/**
* Update day picker
* Recreate list of days when ajax finish
**/
updateDayPicker(data) {
this.datepicker.$day.html('');
for (let day of data) {
Expand All @@ -84,6 +88,10 @@ export default class AgendaTile {
this.datepicker.$day.append($day);
}
}
/**
* Day Click Event
* When click a day need to show the appointments of selected day, and upgate the list of days
**/
onDayClick(e) {
e.preventDefault();
let day = e.target;
Expand Down

0 comments on commit e19dd36

Please sign in to comment.