mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
add percentages to sidelinks
This commit is contained in:
parent
0e036c5493
commit
dd2f03c285
@ -90,6 +90,20 @@ class ContentSerializer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Do a little number crunching
|
||||
self.data[:categories].each do |category|
|
||||
completed_fields = category[:fields].select { |field| field[:value].present? }.count.to_f
|
||||
total_fields = category[:fields].count
|
||||
|
||||
if total_fields.zero?
|
||||
category[:percent_complete] = nil
|
||||
else
|
||||
category[:percent_complete] = (completed_fields / total_fields * 100).round
|
||||
end
|
||||
end
|
||||
|
||||
self.data
|
||||
end
|
||||
|
||||
def value_for(attribute_field, content)
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
<% if creating || editing %>
|
||||
<button class="btn waves-effect waves-<%= raw_model.class.color %> <%= raw_model.class.color %> mp-sidebar-save" type="submit" name="action"
|
||||
style="margin: 10px 0 10px 0; width: 100%">
|
||||
style="margin: 20px 0 10px 0; width: 100%">
|
||||
<i class="material-icons left">save</i>
|
||||
<%= raw_model.new_record? ? 'Create' : 'Save Changes' %>
|
||||
</button>
|
||||
|
||||
@ -45,8 +45,14 @@
|
||||
<a href="#<%= category[:name].gsub("'", '') %>_panel" class="<%= 'red-text' if category[:label] == 'Overview' %>">
|
||||
<i class="material-icons left"><%= category[:icon] %></i>
|
||||
<%= category[:label].capitalize.presence || '(blank)' %>
|
||||
<% if editing %>
|
||||
<span class="badge"><%= rand(100) %>%</span>
|
||||
<% if editing && category[:percent_complete].present? %>
|
||||
<span class="badge">
|
||||
<% if category[:percent_complete] == 100 %>
|
||||
<i class="material-icons green-text">check</i>
|
||||
<% else %>
|
||||
<%= category[:percent_complete] %>%
|
||||
<% end %>
|
||||
</span>
|
||||
<% end %>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user