Skip to content

Commit

Permalink
Merge branch 'aiccra-tip-integration' into aiccra-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjitm committed Jan 16, 2024
2 parents 393ac72 + bcc3ca8 commit f2131e2
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* This file is part of Managing Agricultural Research for Learning&*Outcomes Platform(MARLO).
** MARLO is free software:you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation,either version 3 of the License,or*at your option)any later version.
** MARLO is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY;without even the implied warranty of*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See
* the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with MARLO.If not,see<http:// www.gnu.org/licenses/>.
*****************************************************************/

package org.cgiar.ccafs.marlo.action.superadmin;

import org.cgiar.ccafs.marlo.action.BaseAction;
import org.cgiar.ccafs.marlo.data.manager.TipParametersManager;
import org.cgiar.ccafs.marlo.data.model.TipParameters;
import org.cgiar.ccafs.marlo.utils.APConfig;
import org.cgiar.ccafs.marlo.validation.superadmin.FeedbackManagementValidator;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.inject.Inject;

import org.jfree.util.Log;


public class TIPManagementAction extends BaseAction {

private static final long serialVersionUID = -793652591843623397L;
private TipParametersManager tipParameterManager;
private TipParameters tipParameter;

@Inject
public TIPManagementAction(APConfig config, TipParametersManager tipParameterManager,
FeedbackManagementValidator validator) {
super(config);
this.tipParameterManager = tipParameterManager;
}

public TipParameters getTipParameter() {
return tipParameter;
}

@Override
public void prepare() throws Exception {
try {
tipParameter = tipParameterManager.findAll().get(0);
} catch (Exception e) {
Log.error("error getting tip parameters " + e);
}
}

@Override
public String save() {
if (this.canAccessSuperAdmin()) {
if (tipParameter != null) {

TipParameters tipParameterSave = new TipParameters();
if (tipParameter.getId() != null) {
tipParameterSave.setId(tipParameter.getId());
}
if (tipParameter.getTipLoginService() != null) {
tipParameterSave.setTipLoginService(tipParameter.getTipLoginService());
}
if (tipParameter.getTipStatusService() != null) {
tipParameterSave.setTipStatusService(tipParameter.getTipStatusService());
}
if (tipParameter.getTipTokenService() != null) {
tipParameterSave.setTipTokenService(tipParameter.getTipTokenService());
}
if (tipParameter.getTokenDueDate() != null) {
tipParameterSave.setTokenDueDate(tipParameter.getTokenDueDate());
}
if (tipParameter.getTokenValue() != null) {
tipParameterSave.setTokenValue(tipParameter.getTokenValue());
}
if (tipParameter.getPrivateKey() != null) {
tipParameterSave.setPrivateKey(tipParameter.getPrivateKey());
}

tipParameterManager.saveTipParameters(tipParameterSave);

}

if (this.getUrl() == null || this.getUrl().isEmpty()) {
Collection<String> messages = this.getActionMessages();
if (this.getInvalidFields() != null && !this.getInvalidFields().isEmpty()) {
this.setActionMessages(null);
// this.addActionMessage(Map.toString(this.getInvalidFields().toArray()));
List<String> keys = new ArrayList<String>(this.getInvalidFields().keySet());
for (String key : keys) {
this.addActionMessage(key + ": " + this.getInvalidFields().get(key));
}
} else {
this.addActionMessage("message:" + this.getText("saving.saved"));
}
return SUCCESS;
} else {
this.addActionMessage("");
this.setActionMessages(null);
return REDIRECT;
}

} else {
return NOT_AUTHORIZED;
}
}

public void setTipParameter(TipParameters tipParameter) {
this.tipParameter = tipParameter;
}

}
14 changes: 13 additions & 1 deletion marlo-web/src/main/resources/custom/aicrra.properties
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ manageUsers.email.notAdded=Something happened\! Please take a screenshot and con
manageUsers.email.validation=Enter both First Name and Last Name.
manageUsers.email.notValid=Please, enter a valid email.
manageUsers.email.roleExisting=The user already has a role in this ptf
# TIP Management
tipParameterManagement.title=TIP Management
tipParameter.privateKey=Private Key
tipParameter.tipTokenService=Token Service Endpoint
tipParameter.tipLoginService=Login Service Endpoint
tipParameter.tipStatusService= Status Service Endpoint
tipParameter.tokenValue= Token Value
tipParameter.updateToken= Update Token
tipParameter.tokenDueDate= Token Due Date
# Header
header.logout=Logout
# Menu
Expand All @@ -230,13 +239,16 @@ menu.superadmin.crossCutting=Cross-Cutting Issues
menu.superadmin.idos=Intermediate Development Outcomes
menu.superadmin.siteIntegration=CGIAR Country Collaboration (CCC)
menu.superadmin.notifications=Notifications

menu.superadmin.feedbackManagement=Feedback Management
menu.superadmin.buttonGuideManagement=Guide Button Management
menu.superadmin.marloMessages=MARLO Messages Management
menu.superadmin.permissions=Permissions
menu.superadmin.parameters=PTF Parameters
menu.superadmin.institutions=Request Institutions
menu.superadmin.customLocations=Locations
menu.superadmin.emails=Emails on track
menu.superadmin.guestUserMessage=Currently not available to assign 'Guest' roles to existing users
menu.superadmin.tipManagement=TIP Management
menu.synthesis=Synthesis
menu.synthesis.crpIndicators=PTF Indicators
menu.synthesis.outcomeSynthesis=Outcome Synthesis
Expand Down
10 changes: 10 additions & 0 deletions marlo-web/src/main/resources/global.properties
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ manageUsers.email.notAdded=Something happened\! Please take a screenshot and con
manageUsers.email.validation=Enter both First Name and Last Name.
manageUsers.email.notValid=Please, enter a valid email.
manageUsers.email.roleExisting=The user already has a role in this crp
# TIP Management
tipParameterManagement.title=TIP Management
tipParameter.privateKey=Private Key
tipParameter.tipTokenService=Token Service Endpoint
tipParameter.tipLoginService=Login Service Endpoint
tipParameter.tipStatusService= Status Service Endpoint
tipParameter.tokenValue= Token Value
tipParameter.updateToken= Update Token
tipParameter.tokenDueDate= Token Due Date
# Header
header.logout=Logout
# Menu
Expand Down Expand Up @@ -240,6 +249,7 @@ menu.superadmin.institutions=Request Institutions
menu.superadmin.customLocations=Locations
menu.superadmin.emails=Emails on track
menu.superadmin.guestUserMessage=Currently not available to assign 'Guest' roles to existing users
menu.superadmin.tipManagement=TIP Management
menu.synthesis=Synthesis
menu.synthesis.crpIndicators=CRP Indicators
menu.synthesis.outcomeSynthesis=Outcome Synthesis
Expand Down
9 changes: 9 additions & 0 deletions marlo-web/src/main/resources/struts-superadmin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,15 @@
<param name="edit">true</param>
</result>
</action>
<action name="tipManagement"
class="org.cgiar.ccafs.marlo.action.superadmin.TIPManagementAction">
<interceptor-ref name="superAdminStack" />
<result name="input">/WEB-INF/global/views/superadmin/tipManagement.ftl</result>
<result name="success" type="redirectAction">
<param name="actionName">tipManagement</param>
<param name="edit">true</param>
</result>
</action>
<action name="buttonGuideManagement"
class="org.cgiar.ccafs.marlo.action.superadmin.ButtonGuideManagementAction">
<interceptor-ref name="superAdminStack" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

[#assign managers= [
{ 'slug': 'marloMessages', 'name': 'menu.superadmin.marloMessages', 'action': 'marloMessages', 'active': true },
{ 'slug': 'tipManagement', 'name': 'menu.superadmin.tipManagement', 'action': 'tipManagement', 'active': true },
{ 'slug': 'timelineManagement', 'name': 'menu.superadmin.timelineManagement', 'action': 'timelineManagement', 'active': true}
{ 'slug': 'feedbackManagement', 'name': 'menu.superadmin.feedbackManagement', 'action': 'feedbackManagement', 'active': true}
{ 'slug': 'buttonGuideManagement', 'name': 'menu.superadmin.buttonGuideManagement', 'action': 'buttonGuideManagement', 'active': true}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[#ftl]
[#assign title = "TIP Management" /]
[#assign currentSectionString = "${actionName?replace('/','-')}-phase-${(actualPhase.id)!}" /]
[#assign pageLibs = [] /]
[#assign customJS = [ "${baseUrlCdn}/global/js/superadmin/tipManagement.js?20231214a", "${baseUrlCdn}/global/js/fieldsValidation.js"
] /]
[#assign customCSS = [ "${baseUrlCdn}/global/css/superadmin/superadmin.css" ] /]
[#assign currentSection = "superadmin" /]
[#assign currentStage = "tipManagement" /]

[#assign breadCrumb = [
{"label":"superadmin", "nameSpace":"", "action":"marloBoard"},
{"label":"tipManagement", "nameSpace":"", "action":""}
]/]

[#include "/WEB-INF/global/pages/header.ftl" /]
<hr />

<div class="container">
[#include "/WEB-INF/global/pages/breadcrumb.ftl" /]
</div>
[#include "/WEB-INF/global/pages/generalMessages.ftl" /]


<section class="marlo-content">
<div class="container">
<div class="row">
<div class="col-md-3">
[#include "/WEB-INF/global/views/superadmin/menu-superadmin.ftl" /]
</div>
<div class="col-md-9">
[@s.form action=actionName enctype="multipart/form-data" ]

[#-- System Level Outcomes --]
<h4 class="sectionTitle">[@s.text name="tipParameterManagement.title" /]</h4>

<div id="tipManagement" class="borderBox">
<div class="form-group">
[@customForm.input name="tipParameter.privateKey" i18nkey="tipParameter.privateKey" className="description limitWords-100" required=true /]
</div>
<div class="clearfix"></div>
<div class="form-group">
[@customForm.input name="tipParameter.tipTokenService" i18nkey="tipParameter.tipTokenService" className="description limitWords-100" required=true /]
</div>
<div class="clearfix"></div>
<div class="form-group ">
[@customForm.input name="tipParameter.tipLoginService" i18nkey="tipParameter.tipLoginService" className="description limitWords-100" required=true /]
</div>
<div class="clearfix"></div>
<div class="form-group">
[@customForm.input name="tipParameter.tipStatusService" i18nkey="tipParameter.tipStatusService" className="description limitWords-100" required=true /]
</div>
<div class="clearfix"></div>
<div class="form-group" style="display:block">
[@customForm.input id="tipParameter.tokenValue" name="tipParameter.tokenValue" i18nkey="tipParameter.tokenValue" className="description limitWords-100" required=true /]
<a id="updateTokenBtn" class="addButton">[@s.text name="tipParameter.updateToken" /]</a>
</div>
<div class="clearfix"></div>
<div class="form-group">
[@customForm.input name="tipParameter.tokenDueDate" i18nkey="tipParameter.tokenDueDate" className="description limitWords-100" required=false editable=false /]
</div>
<div class="clearfix"></div>
</div>


[#-- Section Buttons--]
<div class="buttons">
<div class="buttons-content">
[@s.submit type="button" name="save" cssClass="button-save"]<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span> [@s.text name="form.buttons.save" /][/@s.submit]
</div>
</div>

[/@s.form]

</div>
</div>
</div>
</section>


[#include "/WEB-INF/global/pages/footer.ftl" /]
28 changes: 28 additions & 0 deletions marlo-web/src/main/webapp/global/js/superadmin/tipManagement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
$(init);

function init(){
updateTipToken();
}

function updateTipToken() {
$("#updateTokenBtn").on("click", function(event) {
$.ajax({
url: baseURL + '/tipTokenService.do',
type: 'POST',
dataType: 'json',
success: function(response) {

var token = response.token;
$("#tipParameter.tokenValue").val(token);
$('input[name="tipParameter.tokenValue"]').val(token);


},
error: function(error) {
console.error('Error getting embedded URL:', error);
}
});
});

}

0 comments on commit f2131e2

Please sign in to comment.