Skip to content
Snippets Groups Projects
Commit 9a45cff0 authored by Joshua Gill's avatar Joshua Gill
Browse files

Merge branch 'develop' into 'issueThirtyNine'

Branch Update

See merge request !104
parents 75623d97 e20ee1f3
Branches
No related tags found
3 merge requests!114LoggingService service class, new method to add a log to the "Logs" table when...,!107Issue complete,!104Branch Update
Showing
with 152 additions and 37 deletions
package com.example.clientproject.service.Utils;
import com.example.clientproject.data.shops.Shops;
import com.example.clientproject.data.userPermissions.UserPermissions;
import com.example.clientproject.data.userPermissions.UserPermissionsRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class CheckUserOwner {
@Autowired
UserPermissionsRepo permissionsRepo;
public boolean checkOwner(int userId, int shopId){
List<UserPermissions> permissions = permissionsRepo.findByShopID(shopId);
for(UserPermissions u:permissions){
if(u.getUser().getUserId() == userId){
if(u.getAdminType().getAdminTypeId() == 2){
return true;
}
}
}return false;
}
}
......@@ -98,7 +98,7 @@ public class BusinessRegisterSaver {
if(tagsLowerList.contains(t.toLowerCase())){
tag = tagsRepo.findByTagNameIgnoreCase(t).get();
}else{
tag = new Tags(t);
tag = new Tags(t.toLowerCase());
tagsRepo.save(tag);
}
......
......@@ -30,4 +30,22 @@ public class UserLinked {
}
} return false;
}
public boolean isAnyAdmin(int userId){
List<UserPermissions> allLinks = userPermRepo.findByUserId(userId);
for(UserPermissions u:allLinks){
if(u.getAdminType().getAdminTypeId() == 2){
return true;
}
}return false;
}
public int userAdminShopId(int userId){
List<UserPermissions> allLinks = userPermRepo.findByUserId(userId);
for(UserPermissions u:allLinks){
if(u.getAdminType().getAdminTypeId() == 2){
return (int) u.getShop().getShopId();
}
}return 0;
}
}
......@@ -6,6 +6,7 @@ import com.example.clientproject.data.socials.Socials;
import com.example.clientproject.data.socials.SocialsRepo;
import com.example.clientproject.data.stampBoards.StampBoards;
import com.example.clientproject.data.stampBoards.StampBoardsRepo;
import com.example.clientproject.data.tags.Tags;
import com.example.clientproject.data.userPermissions.UserPermissions;
import com.example.clientproject.data.userPermissions.UserPermissionsRepo;
import com.example.clientproject.data.userStampBoards.UserStampBoards;
......@@ -110,9 +111,18 @@ public class BusinessDetails {
UserStampPosOBJ.add(UserStampPos);
model.addAttribute("UserStampPos", UserStampPosOBJ);
String tags = "Tags: ";
for(int i=0; i<shop.getShopTags().size(); i++){
if(i != shop.getShopTags().size()-1){
tags+=shop.getShopTags().get(i).getTagName() + ", ";
}else{
tags += shop.getShopTags().get(i).getTagName();
}
}
//model.addAttribute("stampBoard", stampBoard);
model.addAttribute("loggedInUser", user.get());
model.addAttribute("tags", tags);
model.addAttribute("shop", shop);
model.addAttribute("stampBoard", stampBoard);
return "shopDetails.html";
......
......@@ -11,6 +11,7 @@ import com.example.clientproject.service.dtos.UsersDTO;
import com.example.clientproject.service.searches.UsersSearch;
import com.example.clientproject.services.BusinessRegisterDTO;
import com.example.clientproject.services.BusinessRegisterSaver;
import com.example.clientproject.services.UserLinked;
import com.example.clientproject.services.UserShopLinked;
import com.example.clientproject.web.forms.BusinessRegisterForm;
import com.example.clientproject.web.forms.signUpAndIn.LoginForm;
......@@ -35,20 +36,20 @@ public class SignInController {
private JWTUtils jwtUtils;
private UserShopLinked userShopLinked;
private UserLinked userLinked;
private UserPermissionsRepo userPermissionsRepo;
private CategoriesRepo catRepo;
public SignInController(UsersSearch aUsersSearch, BusinessRegisterSaver sBusiness, JWTUtils ajwtUtils,
UserShopLinked aUserShopLinked,
UserLinked aUserShopLinked,
UserPermissionsRepo aUserPermissionsRepo,
CategoriesRepo aCatRepo) {
usersSearch = aUsersSearch;
saveBusiness = sBusiness;
jwtUtils = ajwtUtils;
userShopLinked = aUserShopLinked;
userLinked = aUserShopLinked;
userPermissionsRepo = aUserPermissionsRepo;
catRepo = aCatRepo;
}
......@@ -72,13 +73,11 @@ public class SignInController {
}
//System.out.println(userShopLinked.hasShop(jwtUtils.getLoggedInUserId(session).get()));
if(userShopLinked.hasShop(jwtUtils.getLoggedInUserId(session).get())){
long userId = jwtUtils.getLoggedInUserId(session).get();
long shopId = userPermissionsRepo.findByUserId(userId).get(0).getShop().getShopId();
if(shopId == 1){
shopId = userPermissionsRepo.findByUserId(userId).get(1).getShop().getShopId();
}
return "redirect:/businessDetails?shopId="+shopId;
if(userLinked.isAnyAdmin(jwtUtils.getLoggedInUserId(session).get())){
int shopId = userLinked.userAdminShopId(jwtUtils.getLoggedInUserId(session).get());
return "redirect:/redirect?url=businessDetails?shopId="+shopId;
}
List<Categories> categories = catRepo.findAll();
model.addAttribute("loggedInUser", user.get());
......
......@@ -11,3 +11,7 @@
justify-content: space-between;
align-items: center;
}
.staffManagementContainer:last-child{
border-bottom: none!important;
}
......@@ -3,25 +3,29 @@ function submit(shopId, email={"value":""}){
if(email.parentElement.children[0].classList.contains("subtitle")){
emailValue = email.parentElement.children[0].innerHTML
email.parentElement.parentElement.remove()
}else{
emailValue = email.parentElement.children[0].value
document.getElementById("staffManagement").innerHTML+=
`<div id="staffManagement">
<div class="staffManagementContainer">
<p class="subtitle is-6" style="width:50%; margin-bottom: 0">${emailValue}</p>
<button class="button is-danger is-outlined" style="border-bottom: 1px solid black"
onclick="submit(${document.getElementById("shopId").value},this);">
<span class="icon is-small">
<i class="fas fa-times is-danger"></i>
</span>
</button>
</div>
<p id="blackLine" class="subtitle is-6" style="border-bottom: 1px solid #00b89c; margin-bottom:1%; width:50%"></p>
</div>`
emailArray = []
document.getElementsByName("staffEmail").forEach(x => emailArray.push(x.innerHTML))
console.log(emailArray)
if(emailArray.includes(emailValue)){
document.getElementById("emailErrorField").innerHTML = "User already added"
return
}
}
if(emailValue == ""){
document.getElementById("emailErrorField").innerHTML = "Field blank"
return
}
document.getElementById("emailErrorField").innerHTML = ""
let params = "shopId="+ shopId
if(emailValue=="") {
params += "&email=" + document.getElementById("emailAddress").value
......@@ -33,7 +37,27 @@ function submit(shopId, email={"value":""}){
xhttp.onload = function() {
if (xhttp.readyState === 4 && xhttp.status === 200) {
var response = xhttp.responseText
if (response == "success"){
if (response == "OK" || response == "USER REMOVED"){
if(email.parentElement.children[0].classList.contains("subtitle")){
email.parentElement.parentElement.remove()
}else{
document.getElementById("staffManagement").innerHTML+=
`<div id="staffManagement">
<div class="staffManagementContainer">
<p class="subtitle is-6 staffEmail" name="staffEmail" style="width:80%; margin-bottom: 0">${emailValue}</p>
<button class="button is-danger is-outlined" style="border-bottom: 1px solid"
onclick="submit(${document.getElementById("shopId").value},this);">
<span class="icon is-small">
<i class="fas fa-times is-danger"></i>
</span>
</button>
</div>
<p id="blackLine" class="subtitle is-6" style="border-bottom: 1px solid; margin-bottom:1%; width:50%"></p>
</div>`
}
}else{
}
} else {
......
var modalStage = 0
var urlInput, urlPrefixInput, nameInput, descInput, tagsInput, amountInput = null;
function keyPress(e) {
if(e.key == "Enter"){
e.preventDefault()
progress()
}if(e.key == "Tab"){
e.preventDefault()
}
}
function htmlDecode(input) {
var doc = new DOMParser().parseFromString(input, "text/html");
return doc.documentElement.textContent;
......@@ -133,6 +142,11 @@ function progress(){
url.value = document.getElementById("business_register_url_prefix").value + url.value;
document.getElementById("businessTags").value = tags;
if(!/^([0-9]+)$/.test(document.getElementById("earnings").value)){
document.getElementById("business_register_amount_help")
.innerHTML = "Please enter a whole number"
return
}
document.getElementById("businessForm").submit();
}
......@@ -200,6 +214,13 @@ function addTag(e){
if(e.data=="," && tags.length != 20){
let inputField = document.forms["businessForm"]["businessTagsInput"]
let text = inputField.value.slice(0,-1);
if(text == ""){
document.getElementById("tagsHelp").innerHTML = "Tag cannot be blank"
document.getElementById("businessTagsInput").value = ""
return
}else{
document.getElementById("tagsHelp").innerHTML = ""
}
document.getElementById("bulmaTags").innerHTML += `
<div>
<div class="control mr-3 mb-2">
......@@ -230,6 +251,7 @@ function addTag(e){
inputField.value = ""
}
}
function removeTag(e){
let text = e.parentElement.children[0].innerHTML
tags = tags.filter(tag =>{return tag!=text});
......
......@@ -73,7 +73,7 @@
<div th:replace="fragments/businessInformation :: keyInformation"></div>
<div th:replace="fragments/userSocials.html :: userSocial"/>
<br>
<th:block th:if="${highestShopLevel>=2}">
<th:block th:if="${@checkUserOwner.checkOwner(loggedInUser.userId, shop.shopId)}">
<div th:replace="fragments/manageStaff.html :: manageStaffMembers"/>
<div th:replace="fragments/deleteShop.html :: deleteShop"/>
<div th:replace="fragments/toggleShop.html :: toggleShop"/>
......
......@@ -49,6 +49,8 @@
total_reward_amount=${shop.getStampBoard.getRewards.size},
img_path=${shop.shopImage},
shopId=${shop.shopId}"></div>
<h1 class="subtitle is-5" th:if="${favouriteShops.size == 0 && activeShops.size == 0}"> Looks like you don't have any stamps yet, favourite a shop or make a purchase to start collecting!</h1>
</div>
......
......@@ -4,14 +4,14 @@
<script th:fragment="infoJs" src="js/businessInformation.js"></script>
</head>
<body th:fragment="keyInformation">
<div style="border-bottom: #000000 1px solid; width:50%">
<div style="width:50%">
<h6 class="title is-6" style="margin-top: 5px; margin-bottom: 25px">Key Information</h6>
<p class="subtitle is-6" style="margin-bottom:3px;margin-top: 10px">Shop Name</p>
<input type="text" th:value="${shop.shopName}" id="nameInput" class="input">
<p class="subtitle is-6" style="margin-bottom:3px;margin-top: 10px">Description</p>
<textarea class="textarea" id="descriptionInput" th:text="${shop.shopDescription}" cols="30" rows="10"></textarea>
<textarea class="textarea" id="descriptionInput" maxlength="250" th:text="${shop.shopDescription}" cols="30" rows="10"></textarea>
<p class="subtitle is-6" style="margin-bottom:3px;margin-top: 10px">Banner</p>
<img class="mb-3" id="bannerPreview" th:src="${shop.shopBanner}" style="margin-top: 5px; max-height: 100px">
......@@ -49,5 +49,6 @@
<button th:onclick="'submitInfo('+ ${shop.shopId} +');'" class="button is-link" style="margin-top:15px; margin-bottom:10px;">Save changes</button>
</div>
<p style="border-bottom: #000000 1px solid;"></p>
</body>
</html>
\ No newline at end of file
......@@ -17,18 +17,18 @@
</span>
</button>
</div>
<p class="help is-danger" id="emailErrorField"></p>
<p><br>Current Admins</p>
<div id="staffManagement"></div>
<div id="staffManagement" th:each="user : ${staffMembers}">
<div class="staffManagementContainer">
<p class="subtitle is-6" th:text="${user.userEmail}" style="width:50%; margin-bottom: 0"></p>
<button class="button is-danger is-outlined" style="border-bottom: 1px solid black" th:onclick="'submit('+${shop.shopId}+',this);'">
<div class="staffManagementContainer" style="margin-bottom:1%;">
<p class="subtitle is-6 staffEmail" name="staffEmail" th:text="${user.userEmail}" style="width:80%; margin-bottom: 0"></p>
<button class="button is-danger is-outlined" th:onclick="'submit('+${shop.shopId}+',this);'">
<span class="icon is-small">
<i class="fas fa-times is-danger"></i>
</span>
</button>
</div>
<p id="blackLine" class="subtitle is-6" style="border-bottom: 1px solid #00b89c; margin-bottom:1%; width:50%"> </p>
</div>
<input id="shopId" class="input is-hidden" th:value="${shop.shopId}">
......
......@@ -81,7 +81,7 @@
</div>
<button class="button is-link" style="margin-top: 5px" th:onclick="'send('+${shop.shopId}+');'">Save changes</button>
</div>
<p style="border-bottom: 1px solid #00b89c;"><br></p>
<p style="border-bottom: 1px solid;"><br></p>
</body>
......
......@@ -28,7 +28,7 @@
<div id="progressBar" class="progressBar">
<div style="width:20%"></div>
</div>
<form name="businessForm" id="businessForm" action="/businessRegister" th:method="post" onsubmit="return false">
<form onkeydown="keyPress(event)" name="businessForm" id="businessForm" action="/businessRegister" th:method="post" onsubmit="return false">
<section class="modal-card-body url-centering" id="modal_container">
<div id="modal_page1" class="modal_page">
<h5 class="title is-5" style="text-align:center">Enter your shop URL</h5>
......@@ -75,10 +75,16 @@
</div>
</div>
<h5 class="title is-5 mt-2" style="text-align:center; margin-bottom: 2%">Add tags that describe your business</h5>
<div class="is-flex is-justify-content-center" style="width:100%;">
<p class="subtitle is-6 mt-1" style="text-align: center">Press comma after typing the tag</p>
<div class="is-flex is-justify-content-center">
<!-- Need to fix this, shouldn't be full width of modal -->
<input id="businessTagsInput" maxlength="50" style="width:75%;" class="input" oninput="addTag(event)"></input>
<div class="is-flex is-flex-direction-column is-justify-content-center is-align-content-center"
style="width:75%">
<input id="businessTagsInput" maxlength="50" class="input" oninput="addTag(event)"></input>
<p class="help is-danger" style="text-align: center" id="tagsHelp"></p>
</div>
<input hidden name="businessTags" id="businessTags"/>
</div>
<div class = "field is-grouped is-grouped-multiline p-4" id="bulmaTags">
<div id="tagCount" style="display: none" class="mr-3">
......
......@@ -119,6 +119,7 @@
</div>
</div>
<div class="content" style="margin-left: 1rem" th:text="${shop.shopDescription}"></div>
<div style="margin-left: 1rem" th:text="${tags}"></div>
<footer class="card-footer">
<a th:href="${shop.shopWebsite}"><p class="card-footer-item websiteLinkText">Click for website<a></a>
</footer>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment