package urteam;

import java.sql.Date;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import urteam.event.*;
import urteam.community.*;
import urteam.user.*;

@Controller
public class urteamController {

	@Autowired
	private UserRepository userRepo;

	@Autowired
	private EventRepository eventRepo;

	@Autowired
	private CommunityRepository communityRepo;

	@PostConstruct
	public void init() {
		
		
		for (int i = 0; i < 10; i++) {
			String name = "Usuario" + i;
			String surname = "apellido" + i;
			String nickname = "user" + surname.substring(1, 3) + i;
			String password = "123456";
			String email = name + surname + i + "@urteam.com";
			userRepo.save(new User(name, surname, nickname, password, email));
		}

		for (int i = 0; i < 10; i++) {
			String name = String.valueOf(i);
			String sport = String.valueOf(i);
			double price = i;
			String info = String.valueOf(i);
			String place = String.valueOf(i);
			Date start_date = new Date(i);
			Date end_date = new Date(i);
			eventRepo.save(new Event(name, sport, price, info, place, start_date, end_date));
		}

		for (int i = 0; i < 10; i++) {
			String name = String.valueOf(i);
			String info = String.valueOf(i);
			communityRepo.save(new Community(name, info, "Running"));
		}
	}

	@RequestMapping("/")
	public String index(Model model) {

		return "index";
	}
	
	@RequestMapping("/adminPanel/edit")
	public String edit(Model model,String action) {
//		switch(action){
//		case "edit": 
//			model.addAttribute("siEdit",true);
//			break;
//		default: model.addAttribute("siEdit",false);
//		}
		model.addAttribute("edit_Section",true);
		return "controlPanel-base";
	}
	
	@RequestMapping("/adminPanel/changePass")
	public String changePass(Model model,String action) {
		model.addAttribute("changePass_Section",true);
		return "controlPanel-base";
	}
	
	@RequestMapping("/adminPanel/manageEvents")
	public String manageEvents(Model model,String action) {
		model.addAttribute("manageEvents_Section",true);
		List<Event> event = eventRepo.findAll();
		model.addAttribute("events",event);
		return "controlPanel-base";
	}
	
	@RequestMapping("/adminPanel/manageUsers")
	public String manageUsers(Model model,String action) {
		model.addAttribute("manageUsers_Section",true);
		return "controlPanel-base";
	}
	
	@RequestMapping("/adminPanel/manageGroups")
	public String manageGroups(Model model,String action) {
		model.addAttribute("manageGroups_Section",true);
		return "controlPanel-base";
	}

}

@@ -1709,20 +1709,24 @@
 inPanel/
-edit
+%7Baction%7D
 %22)%0A%09publ
@@ -1735,20 +1735,20 @@
  String 
-edit
+goTo
 (Model m
@@ -1744,32 +1744,47 @@
 oTo(Model model,
+ @PathVariable 
 String action) %7B
@@ -1785,13 +1785,10 @@
 ion)
- 
 %7B%0A
-//
 %09%09sw
@@ -1801,18 +1801,16 @@
 ction)%7B%0A
-//
 %09%09case %22
@@ -1819,12 +1819,9 @@
 it%22:
- %0A//
+%0A
 %09%09%09m
@@ -1843,198 +1843,51 @@
 te(%22
-siEdit%22,true);%0A//%09%09%09break;%0A//%09%09default: model.addAttribute(%22siEdit%22,false);%0A//%09%09%7D%0A%09%09model.addAttribute(%22edit_Section%22,true);%0A%09%09return %22controlPanel-base%22;%0A%09%7D%0A%09%0A%09@RequestMapping(%22/adminPanel/
+edit_Section%22,true);%0A%09%09%09break;%0A%09%09%09%0A%09%09case %22
 chan
@@ -1897,65 +1897,11 @@
 ass%22
-)
+:
 %0A%09
-public String changePass(Model model,String action) %7B%0A
 %09%09mo
@@ -1951,71 +1951,28 @@
 ;%0A%09%09
-return %22controlPanel-base%22
+%09break
 ;%0A%09
-%7D%0A
 %09%0A%09
-@RequestMapping(%22/adminPanel/
+%09case  %22
 mana
@@ -1984,334 +1984,100 @@
 nts%22
-)%0A%09public String manageEvents(Model model,String action) %7B%0A%09%09model.addAttribute(%22manageEvents_Section%22,true);%0A%09%09List%3CEvent%3E event = eventRepo.findAll();%0A%09%09model.addAttribute(%22events%22,event);%0A%09%09return %22controlPanel-base%22;%0A%09%7D%0A%09%0A%09@RequestMapping(%22/adminPanel/manageUsers%22)%0A%09public String manageUsers(Model model,String action) %7B%0A
+:%0A%09%09%09model.addAttribute(%22manageEvents_Section%22,true);%0A%09%09%09break;%0A%09%09%09%0A%09%09case  %22manageUsers%22:%0A%09
 %09%09mo
@@ -2128,71 +2128,29 @@
 ;%0A%09%09
-return %22controlPanel-base%22;%0A%09%7D%0A%09%0A%09@RequestMapping(%22/adminPanel/
+%09break;%0A%09%09%09%0A%09%09case  %22
 mana
@@ -2162,69 +2162,88 @@
 ups%22
-)%0A%09public String manageGroups(Model model,String action) %7B%0A%09%09
+:%0A%09%09%09model.addAttribute(%22manageGroups_Section%22,true);%0A%09%09%09break;%0A%09%09%09%0A%09%09default : 
 mode
@@ -2254,36 +2254,28 @@
 dAttribute(%22
-manageGroups
+edit
 _Section%22,tr
@@ -2279,16 +2279,23 @@
 ,true);%0A
+%09%09%0A%09%09%7D%0A
 %09%09return

Fix Control Panel Menu. Create switch statement to change page.