add percentages to sidelinks

This commit is contained in:
Andrew Brown 2020-02-19 15:54:40 -06:00
parent 0e036c5493
commit dd2f03c285
3 changed files with 23 additions and 3 deletions

View File

@ -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)

View File

@ -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>

View File

@ -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>