Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladay committed Jun 21, 2023
1 parent 09df3e4 commit 8f54f1b
Show file tree
Hide file tree
Showing 14 changed files with 689 additions and 435 deletions.
30 changes: 20 additions & 10 deletions src/main/java/org/tdl/vireo/controller/OrganizationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
import static org.springframework.beans.BeanUtils.copyProperties;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.tamu.weaver.response.ApiResponse;
import edu.tamu.weaver.response.ApiView;
import edu.tamu.weaver.validation.aspect.annotation.WeaverValidatedModel;
import edu.tamu.weaver.validation.aspect.annotation.WeaverValidation;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -35,15 +41,7 @@
import org.tdl.vireo.model.repo.SubmissionRepo;
import org.tdl.vireo.model.repo.SubmissionStatusRepo;
import org.tdl.vireo.model.repo.WorkflowStepRepo;

import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import edu.tamu.weaver.response.ApiResponse;
import edu.tamu.weaver.response.ApiView;
import edu.tamu.weaver.validation.aspect.annotation.WeaverValidatedModel;
import edu.tamu.weaver.validation.aspect.annotation.WeaverValidation;
import org.tdl.vireo.view.TreeOrganizationView;

@RestController
@RequestMapping("/organization")
Expand Down Expand Up @@ -83,12 +81,24 @@ public ApiResponse allOrganizations() {
return new ApiResponse(SUCCESS, organizationRepo.findAllByOrderByIdAsc());
}

@RequestMapping("/all/tree")
@PreAuthorize("hasRole('STUDENT')")
public ApiResponse getTreeAllOrganizations() {
return new ApiResponse(SUCCESS, organizationRepo.findViewAllByOrderByIdAsc(TreeOrganizationView.class));
}

@RequestMapping("/get/{id}")
@PreAuthorize("hasRole('STUDENT')")
public ApiResponse getOrganization(@PathVariable Long id) {
return new ApiResponse(SUCCESS, organizationRepo.read(id));
}

@RequestMapping("/get/{id}/tree")
@PreAuthorize("hasRole('STUDENT')")
public ApiResponse getTreeViewOrganization(@PathVariable Long id) {
return new ApiResponse(SUCCESS, organizationRepo.findViewById(id, TreeOrganizationView.class));
}

@RequestMapping(value = "/create/{parentOrgID}", method = POST)
@PreAuthorize("hasRole('MANAGER')")
@WeaverValidation(business = { @WeaverValidation.Business(value = CREATE) })
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/tdl/vireo/model/Organization.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@ public Organization(String name, OrganizationCategory category) {
setCategory(category);
}

/**
* @return True.
*/
public boolean isComplete() {
return true;
}

/**
* @return the name
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/tdl/vireo/model/repo/OrganizationRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

public interface OrganizationRepo extends WeaverRepo<Organization>, OrganizationRepoCustom {

public <T> T findViewById(Long id, Class<T> type);

public <T> List<T> findViewAllByOrderByIdAsc(Class<T> type);

public List<Organization> findAllByOrderByIdAsc();

public List<Organization> findByAggregateWorkflowStepsId(Long workflowStepId);
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/tdl/vireo/view/TreeOrganizationView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.tdl.vireo.view;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import java.util.Set;
import org.tdl.vireo.model.OrganizationCategory;

public interface TreeOrganizationView extends SimpleOrganizationView {

public OrganizationCategory getCategory();

public Boolean getAcceptsSubmissions();

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, scope = TreeOrganizationView.class, property = "id")
@JsonIdentityReference(alwaysAsId = true)
public TreeOrganizationView getParentOrganization();

public Set<TreeOrganizationView> getChildrenOrganizations();
}
4 changes: 2 additions & 2 deletions src/main/webapp/app/config/apiMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,10 @@ var apiMapping = {
Organization: {
validations: true,
channel: "/channel/organization",
all: {
allTree: {
'endpoint': '/private/queue',
'controller': 'organization',
'method': 'all'
'method': 'all/tree'
},
addEmailWorkflowRule: {
'endpoint': '/private/queue',
Expand Down
66 changes: 49 additions & 17 deletions src/main/webapp/app/controllers/organizationSettingsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,43 @@ vireo.controller('OrganizationSettingsController', function ($controller, $scope
"viewUrl": "views/sideboxes/organization.html"
});

$scope.organizations = OrganizationRepo.getAll();
$scope.organizations = [];

$scope.activeManagementPane = 'edit';

$scope.newOrganization = OrganizationRepo.getNewOrganization();

$scope.setSelectedOrganization = function (organization) {
var selectedOrganization = OrganizationRepo.getSelectedOrganization();
if (selectedOrganization !== undefined && selectedOrganization.id !== organization.id) {
AccordionService.closeAll();
var selectedOrganization;

$scope.getSelectedOrganization = function () {
if (!!selectedOrganization && selectedOrganization.id) {
console.log("DEBUG: already loaded, returning: ", $scope.organizations[i]);
return selectedOrganization;
}

if ($scope.ready) {
var selectedId = OrganizationRepo.getSelectedId();

if (selectedId !== undefined && $scope.organizations.length > 0) {
for (var i = 0; i < $scope.organizations.length; i++) {
if ($scope.organizations[i].id === selectedId) {
console.log("DEBUG: returning: ", $scope.organizations[i]);
selectedOrganization = $scope.organizations[i];
return $scope.organizations[i];
}
}
}
}
};

$scope.setSelectedOrganization = function (organization) {
OrganizationRepo.setSelectedOrganization(organization);
$scope.newOrganization.parent = OrganizationRepo.getSelectedOrganization();

selectedOrganization = organization;
};

$scope.getSelectedOrganization = function () {
return OrganizationRepo.getSelectedOrganization();
$scope.findOrganizationById = function (orgId) {
return OrganizationRepo.findOrganizationById(orgId, $scope.organizations, 'tree');
};

$scope.activateManagementPane = function (pane) {
Expand All @@ -38,16 +58,28 @@ vireo.controller('OrganizationSettingsController', function ($controller, $scope
return ($scope.activeManagementPane === pane);
};

$q.all([OrganizationRepo.ready()]).then(function () {
$scope.newOrganization.parent = $scope.organizations[0];
});

$scope.setDeleteDisabled = function () {
OrganizationRepo.ready().then(function () {
OrganizationRepo.countSubmissions($scope.getSelectedOrganization().id).then(function (res) {
$scope.deleteDisabled = res > 0;
});
});
if ($scope.ready) {
var organization = $scope.getSelectedOrganization();

if (organization && !!organization.id) {
OrganizationRepo.countSubmissions(organization.id).then(function (res) {
$scope.deleteDisabled = res > 0;
});
}
}
};

OrganizationRepo.defer().then(function (orgs) {
if (!!orgs && orgs.length > 0) {
OrganizationRepo.setSelectedOrganization(orgs[0]);

for (var i = 0; i < orgs.length; i++) {
$scope.organizations.push(orgs[i]);
}
}

$scope.ready = true;
});

});
Loading

0 comments on commit 8f54f1b

Please sign in to comment.