Commit 0baeae07 authored by o@immerda.ch's avatar o@immerda.ch
Browse files

support for resource quotas

parent 5f81c42a
......@@ -346,6 +346,10 @@ module ApiBackend
get(['resource', 'available'])['available']
end
def resource_quota
get(['resource', 'quota'])['quota']
end
def my_resources()
get ['resource', 'mine']
end
......
......@@ -18,6 +18,7 @@ class ResourcesController < ApplicationController
def create
flash[:warning] = nil
@resource_names = list_of_canonical_resources
@resource_quota = api.resource_quota
@resource_name = params[:resource_name]
@resource_name = nil unless @resource_names.include?(@resource_name)
if @resource_name
......
......@@ -22,7 +22,7 @@
invites: ({} if allow_invites?),
delete_account: {},
services: ({divider: true} if (any_resource_enabled? || any_resource_exists?)),
new_resource: ({} if feature_toggle?('resource')),
new_resource: ({}),
}.merge(
list_of_canonical_resources.map do |name|
if resource_exists?(name)
......
......@@ -15,10 +15,21 @@
<p>
<% if @resource_name && !@disabled %>
<%
q = @resource_quota[@resource_name]
allowed = [q['max'].to_i - q['cur'].to_i, 0].max
%>
<div class="alert" role="alert">
<%= t("#{@resource_name}_description") %>
<br />
<%= t(:quota_msg, count: allowed) %>
</div>
<% if allowed > 0 %>
<%= form_tag do %>
<%= hidden_field_tag 'resource_name', @resource_name %>
......@@ -37,5 +48,6 @@
<%= submit_tag t(:create), name: 'create', class: "btn btn-primary" %>
<% end %>
<% end %>
<% end %>
</p>
......@@ -220,6 +220,11 @@ de:
paid: bezahlt
bill_thanks: "Wir danken dir sehr herzlich, dass du im Jahr %{year} %{amount} an immerda.ch gespendet hast!"
quota_msg:
zero: "Du hast alle aufgebraucht. Kontaktiere uns wenn du mehr brauchst"
other: "Du kannst aktuell noch %{count} neue erstellen."
one: "Du kannst aktuell noch eine neue erstellen."
activerecord:
errors:
messages:
......
......@@ -221,6 +221,11 @@ en:
paid: paid
bill_thanks: "Thank you very much for donating a total of %{amount} to immerda.ch in the year %{year}!"
quota_msg:
zero: "You have exceeded you resources. Contact us if you need more."
one: "You can still create one."
other: "You can still create up to %{count} fresh ones."
activerecord:
errors:
messages:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment