Skip to content

Commit

Permalink
closes #867
Browse files Browse the repository at this point in the history
  • Loading branch information
ppazos committed Mar 7, 2018
1 parent 2f6d865 commit e704682
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 32 deletions.
4 changes: 2 additions & 2 deletions grails-app/conf/BootStrap.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ class BootStrap {
new RequestMap(url: '/account/index', configAttribute: 'ROLE_ADMIN').save()
new RequestMap(url: '/account/create', configAttribute: 'ROLE_ADMIN').save()
new RequestMap(url: '/account/save', configAttribute: 'ROLE_ADMIN').save()
new RequestMap(url: '/account/edit', configAttribute: 'ROLE_ADMIN').save()
new RequestMap(url: '/account/edit/**', configAttribute: 'ROLE_ADMIN').save()
new RequestMap(url: '/account/update', configAttribute: 'ROLE_ADMIN').save()
new RequestMap(url: '/account/show/**', configAttribute: 'ROLE_ADMIN,ROLE_ACCOUNT_MANAGER,ROLE_ORG_MANAGER').save()

Expand Down Expand Up @@ -991,7 +991,7 @@ gr_account.save(failOnError:true, flush:true)
max_organizations: 3,
max_opts_per_organization: 3,
max_api_tokens_per_organization: 3,
repo_total_size_in_kb: 900, // low for testing! (1MB in KB)
repo_total_size_in_kb: 2000, // low for testing! (1MB in KB)
period: Plan.periods.MONTHLY
)
]
Expand Down
18 changes: 9 additions & 9 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ grails.reload.enabled = true
forkConfig = [maxMemory: 1024, minMemory: 64, debug: false, maxPerm: 512]
grails.project.fork = [
test: forkConfig, // configure settings for the test-app JVM
run: false, // configure settings for the run-app JVM
run: forkConfig, // configure settings for the run-app JVM
war: forkConfig, // configure settings for the run-war JVM
console: forkConfig // configure settings for the Swing console JVM
]
Expand Down Expand Up @@ -73,7 +73,7 @@ grails.project.dependency.resolution = {

mavenLocal()
mavenCentral()

mavenRepo "http://repo.spring.io/milestone/"
//mavenRepo "https://oss.sonatype.org/content/repositories/snapshots/"

Expand All @@ -87,7 +87,7 @@ grails.project.dependency.resolution = {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

// runtime 'mysql:mysql-connector-java:5.1.20'

// Este error da si uso http-builder 0.6 con 0.5.2 anda ok
// FIX: Me da un error luego de poner referencia a http-builder
// http://jira.grails.org/browse/GPEXPORT-18?focusedCommentId=69307&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-69307
Expand All @@ -100,26 +100,26 @@ grails.project.dependency.resolution = {
excludes 'xmlbeans'
}
*/

/*
runtime('com.thoughtworks.xstream:xstream:1.4.3') {
// loader constraint violation: loader (instance of <bootloader>) previously
// initiated loading for a different type with name "org/w3c/dom/TypeInfo"
//excludes 'xmlbeans'
}
*/

runtime('org.codehaus.groovy.modules.http-builder:http-builder:0.5.2') {
excludes "commons-logging", "xml-apis", "groovy", "nekohtml"
}

test "org.grails:grails-datastore-test-support:1.0-grails-2.4"

//compile 'xerces:xercesImpl:2.11.0'
compile group: 'de.odysseus.staxon', name: 'staxon', version: '1.2'

compile "mysql:mysql-connector-java:5.1.43" //"mysql:mysql-connector-java:5.1.22"

//compile "org.springframework.security:spring-security-crypto:4.0.2-RELEASE"
//compile 'org.pac4j:pac4j-core:1.7.1'
}
Expand All @@ -146,7 +146,7 @@ grails.project.dependency.resolution = {
runtime ':hibernate4:4.3.10' // or ':hibernate:3.6.10.14'
runtime ':database-migration:1.4.0'
runtime ':jquery:1.11.1'

// https://github.com/davidtinker/grails-cors
runtime ":cors:1.1.8"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package com.cabolabs.ehrserver.account

import net.kaleidos.grails.plugin.security.stateless.annotation.SecuredStateless

import com.cabolabs.ehrserver.ehr.clinical_documents.OperationalTemplateIndex
import com.cabolabs.ehrserver.openehr.common.change_control.Contribution
import com.cabolabs.ehrserver.openehr.common.change_control.Version
import com.cabolabs.security.*
Expand Down Expand Up @@ -149,6 +150,7 @@ class StatsController {
from: from, to: to]
}

// disk usage for all the organizations in the account
// results are in KB
def accountRepoUsage(Account account)
{
Expand All @@ -173,9 +175,40 @@ class StatsController {
// size is set in KB
stats[org.uid] = size

if (!plan_repo_total_size) max_repo_size += stats[org.name]
// if there is no plan, we set the max to the current size
if (!plan_repo_total_size) max_repo_size += size
}

render(text: [max_repo_size: max_repo_size, usage: stats] as JSON, contentType:"application/json", encoding:"UTF-8")
}

/**
* Stats abuot the number of templates loaded, returns also the max templates per org.
*/
def accountTemplatesLoaded(Account account)
{
def plan_association = Plan.active(account) // can be null!
def max_opts_per_org = 0

def plan_max_opts = false
if (plan_association)
{
max_opts_per_org = plan_association.plan.max_opts_per_organization
plan_max_opts = true
}

def stats = [:] // org name => repo size
def count

account.organizations.each { org ->

count = OperationalTemplateIndex.forOrg(org).lastVersions.count()
stats[org.uid] = count

// if there is no plan, we set the max to the current amount
if (!plan_max_opts) max_opts_per_org += count
}

render(text: [max_opts_per_org: max_opts_per_org, usage: stats] as JSON, contentType:"application/json", encoding:"UTF-8")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class OperationalTemplateController {

def user = springSecurityService.getCurrentUser()

// Repo size check
// Repo size check and max opt check max_opts_per_organization
def account = user.account
def plan_assoc = Plan.active(account) // can be null on dev envs, size check is not done on that case.
if (plan_assoc)
Expand All @@ -102,14 +102,25 @@ class OperationalTemplateController {
render(text: res as JSON, contentType:"application/json", encoding:"UTF-8")
return
}

def opt_count = OperationalTemplateIndex.forOrg(session.organization).lastVersions.count()

if (plan_assoc.plan.max_opts_per_organization <= opt_count)
{
res = [status:'error', message:message(code:'opt.upload.error.max_opt_reached'), errors: errors]
render(text: res as JSON, contentType:"application/json", encoding:"UTF-8")
return
}
}



// PROCESS FILE

// http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/multipart/commons/CommonsMultipartFile.html
def f = request.getFile('opt')

// Add file empty check
// file empty check
if(f.empty)
{
errors << message(code:"opt.upload.error.noOPT")
Expand Down Expand Up @@ -142,6 +153,7 @@ class OperationalTemplateController {

// /PROCESS FILE


// ROOT VALIDATION

// Parse to get the template id
Expand Down
2 changes: 2 additions & 0 deletions grails-app/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ opt.upload.label.overwrite=Overwrite if template exists
opt.upload.label.opt=Operational Template
opt.upload.label.upload=Upload
opt.upload.error.insufficient_storage=You have reached the storage limit for your account. If you need more storage, please upgrade your plan. Contact [email protected] for more information.
opt.upload.error.max_opt_reached=You have reached the maximum amount of templates for this organization. If you need more, please upgrade your plan. Contact [email protected] for more information.

template.show.title=Template details
template.templateId.label=Template ID
Expand Down Expand Up @@ -687,6 +688,7 @@ account.update.planNotFound=Plan not found
account.update.errorAssigningPlan=Plan assignment returned an error
account.update.ok=Account updated!
account.stats.repo_usage=Disk usage
account.stats.uploaded_opts=Uploaded templates

account.create.title=Create account
account.attr.companyName=Company name
Expand Down
2 changes: 2 additions & 0 deletions grails-app/i18n/messages_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ opt.upload.label.overwrite=Sobreescribir si existe
opt.upload.label.opt=Plantilla
opt.upload.label.upload=Cargar
opt.upload.error.insufficient_storagee=Ha alcanzado el límite de almacenamiento para su cuenta. Si necesita más espacio de almacenamiento, por favor mejore su plan. Contacte [email protected] para más información.
opt.upload.error.max_opt_reached=Ha alcanzado el número máximo de plantillas para esta organización. Si necesita más, por favor mejore su plan. Contacte [email protected] para más información.

template.show.title=Plantilla
template.templateId.label=ID
Expand Down Expand Up @@ -687,6 +688,7 @@ account.update.planNotFound=El plan no existe
account.update.errorAssigningPlan=Ocurrió un error al asignar el plan
account.update.ok=Cuenta actualizada con éxito
account.stats.repo_usage=Uso de disco
account.stats.uploaded_opts=Plantillas cargadas

account.create.title=Crear cuenta
account.attr.companyName=Nombre de la empresa
Expand Down
10 changes: 6 additions & 4 deletions grails-app/views/account/index.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<title><g:message code="account.index.title" /></title>
</head>
<body>

<div class="row">
<div class="col-lg-12">
<h1><g:message code="account.index.title" /></h1>
</div>
</div>

<div class="row row-grid">
<div class="col-md-12">
<div class="btn-toolbar" role="toolbar">
Expand All @@ -27,7 +27,7 @@
</div>
</div>
</div>

<div class="row row-grid">
<div class="col-lg-12">
<g:if test="${flash.message}">
Expand All @@ -37,14 +37,16 @@
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th><g:message code="account.attr.companyName" default="Company name" /></th>
<th><g:message code="account.attr.contact" default="Contact" /></th>
<g:sortableColumn property="enabled" title="${message(code: 'account.attr.enabled', default: 'Enabled')}" />
</tr>
</thead>
<tbody>
<g:each in="${accounts}" status="i" var="accountInstance">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td><g:link action="show" id="${accountInstance.id}">${fieldValue(bean: accountInstance, field: "contact")}</g:link></td>
<td><g:link action="show" id="${accountInstance.id}">${accountInstance.companyName}</g:link></td>
<td>${accountInstance.contact}</td>
<td><g:formatBoolean boolean="${accountInstance.enabled}" /></td>
</tr>
</g:each>
Expand Down
46 changes: 34 additions & 12 deletions grails-app/views/account/show.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,26 @@
</g:if>
</th>
<td>
<ul>
<g:each in="${account.organizations}" var="org">
<li>
<g:link controller="organization" action="show" params="[uid: org.uid]">${org.name}</g:link>
<span id="${org.uid}"></span>
</li>
</g:each>
</ul>
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover table-org-roles">
<thead>
<tr>
<th><g:message code="organization.name.label" default="Organization" /></th>
<th><g:message code="stats.org.storageUsagePercentage" default="Storage usage %" /></th>
<th><g:message code="stats.org.loadedTemplates" default="Loaded templates" /></th>
</tr>
</thead>
<tbody>
<g:each in="${account.organizations}" var="org">
<tr>
<td><g:link controller="organization" action="show" params="[uid: org.uid]">${org.name}</g:link></td>
<td><span id="stats-storage-${org.uid}"></span></td>
<td><span id="stats-opts-${org.uid}"></span></td>
</tr>
</g:each>
</tbody>
</table>
</div>
</td>
</tr>
</table>
Expand Down Expand Up @@ -82,20 +94,30 @@
.done( function(json) {
console.log('stats', json);
var classes = ['success', 'info', 'warning', 'danger'];
var bar = $('<div class="progress"></div>');
var org_count = Object.keys(json.usage).length;
var i = 0;
for (org_uid in json.usage)
{
percent = precisionRound( json.usage[org_uid] * 100 / json.max_repo_size, 1);
$('#'+ org_uid).text(percent +'%').append(' <i class="fa fa-database" aria-hidden="true" title="${message(code:'account.stats.repo_usage')}"></i>');
$('#stats-storage-'+ org_uid).text(percent +'%').append(' <i class="fa fa-database" aria-hidden="true" title="${message(code:'account.stats.repo_usage')}"></i>');
i++;
}
});
$('#account_stats').append(bar);
$.ajax({
url: '${createLink(controller:"stats", action:"accountTemplatesLoaded", id:account.id)}',
method: 'GET',
dataType: 'json'
})
.done( function(json) {
console.log('stats', json);
for (org_uid in json.usage)
{
$('#stats-opts-'+ org_uid).text(json.usage[org_uid] +' / '+ json.max_opts_per_org).append(' <i class="fa fa-cubes" aria-hidden="true" title="${message(code:'account.stats.uploaded_opts')}"></i>');
}
});
});
</script>
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/organization/_form.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<label for="accounts">
<g:message code="organization.accounts.label" default="Accounts" />
</label>
<g:select from="${accounts}" name="account_id" optionKey="id" optionValue="contact" class="form-control"></g:select>
<g:select from="${accounts}" name="account_id" optionKey="id" optionValue="companyName" class="form-control"></g:select>
</div>
</g:if>
</sec:ifAnyGranted>
2 changes: 1 addition & 1 deletion lrun.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
grails -Dserver.port=8090 -Duser.timezone=UTC run-app
grails -Dserver.port=8090 -Duser.timezone=UTC -reloading run-app

0 comments on commit e704682

Please sign in to comment.