Sfoglia il codice sorgente

Many improvements on class; add student model

Andrea Fazzi 6 anni fa
parent
commit
0b435faeb9

+ 20 - 4
orm/activity.go

@@ -26,10 +26,14 @@ type Activity struct {
 }
 
 type ActivityForUpdate struct {
-	Activity        Activity
-	AllClasses      []*Class
-	AllSubjects     []*Subject
-	AllTeachers     []*Teacher
+	Activity Activity
+
+	AllClasses  []*Class
+	AllSubjects []*Subject
+	AllTeachers []*Teacher
+	AllStudents []*Student
+
+	SelectedStudent map[uint]string
 	SelectedTeacher map[uint]string
 	SelectedSubject map[uint]string
 	SelectedClass   map[uint]string
@@ -39,6 +43,7 @@ type ActivityForAdd struct {
 	AllClasses  []*Class
 	AllSubjects []*Subject
 	AllTeachers []*Teacher
+	AllStudents []*Student
 }
 
 func (a *Activity) GetID() uint { return a.ID }
@@ -83,9 +88,16 @@ func GetActivityForUpdate(args map[string]string) (interface{}, error) {
 		return nil, err
 	}
 
+	if err := DB().Find(&data.AllStudents).Error; err != nil {
+		return nil, err
+	}
+
 	data.SelectedTeacher = make(map[uint]string)
 	data.SelectedTeacher[data.Activity.TeacherID] = "selected"
 
+	data.SelectedStudent = make(map[uint]string)
+	data.SelectedStudent[data.Activity.StudentID] = "selected"
+
 	data.SelectedClass = make(map[uint]string)
 	data.SelectedClass[data.Activity.ClassID] = "selected"
 
@@ -109,6 +121,10 @@ func GetActivityForAdd(args map[string]string) (interface{}, error) {
 		return nil, err
 	}
 
+	if err := DB().Find(&data.AllStudents).Error; err != nil {
+		return nil, err
+	}
+
 	return data, nil
 }
 

+ 14 - 6
orm/class.go

@@ -19,14 +19,22 @@ WHERE class_id=?
 
 type Class struct {
 	gorm.Model
-	Name          string
+
+	Name    string
+	Alias   string
+	Year    int
+	Section string
+	Field   string
+
 	CoordinatorID uint `schema:"coordinator_id"`
 	MinuterID     uint `schema:"minuter_id"`
-	Coordinator   Teacher
-	Minuter       Teacher
-	Teachers      []*Teacher
-	Activities    []*Activity
-	Students      []*Student
+
+	Coordinator Teacher
+	Minuter     Teacher
+
+	Teachers   []*Teacher
+	Activities []*Activity
+	Students   []*Student
 }
 
 type ClassForUpdate struct {

+ 13 - 10
orm/compose/sql/karmen_test.sql

@@ -32,9 +32,10 @@ CREATE TABLE `activities` (
   `teacher_id` int(10) unsigned DEFAULT NULL,
   `subject_id` int(10) unsigned DEFAULT NULL,
   `hours` int(11) DEFAULT NULL,
+  `student_id` int(10) unsigned DEFAULT NULL,
   PRIMARY KEY (`id`),
   KEY `idx_activities_deleted_at` (`deleted_at`)
-) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
+) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=latin1;
 /*!40101 SET character_set_client = @saved_cs_client */;
 
 --
@@ -43,7 +44,7 @@ CREATE TABLE `activities` (
 
 LOCK TABLES `activities` WRITE;
 /*!40000 ALTER TABLE `activities` DISABLE KEYS */;
-INSERT INTO `activities` VALUES (1,'2018-08-24 17:17:22','2018-08-24 17:17:22',NULL,'1 A MATEMATICA 2h',1,1,1,2),(2,'2018-08-24 17:18:01','2018-08-24 17:18:01',NULL,'1 A INGLESE 2h',1,2,3,2),(3,'2018-08-24 17:18:26','2018-08-24 17:18:26',NULL,'1 A ITALIANO 5h',1,3,2,5),(4,'2018-08-24 17:23:58','2018-08-24 17:23:58',NULL,'1 A STORIA DELL\'ARTE 2h',1,5,4,2),(5,'2018-08-24 17:24:20','2018-08-24 17:24:20',NULL,'1 A TECNOLOGIA 2h',1,4,9,2),(6,'2018-08-24 17:24:41','2018-08-24 17:24:41',NULL,'1 A FRANCESE 2h',1,7,7,2),(7,'2018-08-24 17:25:13','2018-08-24 17:25:13',NULL,'1 A RELIGIONE 2h',1,9,6,2),(8,'2018-08-24 17:25:44','2018-08-24 17:25:44',NULL,'1 A STORIA 2h',1,6,8,2),(9,'2018-08-24 17:26:15','2018-08-24 17:26:15',NULL,'1 A SCIENZE 2h',1,8,5,2);
+INSERT INTO `activities` VALUES (1,'2018-08-24 17:17:22','2018-08-24 17:17:22',NULL,'1 A MATEMATICA 2h',1,1,1,2,NULL),(2,'2018-08-24 17:18:01','2018-08-24 17:18:01',NULL,'1 A INGLESE 2h',1,2,3,2,NULL),(3,'2018-08-24 17:18:26','2018-08-24 17:18:26',NULL,'1 A ITALIANO 5h',1,3,2,5,NULL),(4,'2018-08-24 17:23:58','2018-08-24 17:23:58',NULL,'1 A STORIA DELL\'ARTE 2h',1,5,4,2,NULL),(5,'2018-08-24 17:24:20','2018-08-24 17:24:20',NULL,'1 A TECNOLOGIA 2h',1,4,9,2,NULL),(6,'2018-08-24 17:24:41','2018-08-24 17:24:41',NULL,'1 A FRANCESE 2h',1,7,7,2,NULL),(7,'2018-08-24 17:25:13','2018-08-24 17:25:13',NULL,'1 A RELIGIONE 2h',1,9,6,2,NULL),(8,'2018-08-24 17:25:44','2018-08-24 17:25:44',NULL,'1 A STORIA 2h',1,6,8,2,NULL),(9,'2018-08-24 17:26:15','2018-08-24 17:26:15',NULL,'1 A SCIENZE 2h',1,8,5,2,NULL),(10,'2018-09-18 09:21:28','2018-09-18 09:21:28',NULL,NULL,1,10,10,5,1),(11,'2018-09-18 09:27:33','2018-09-18 09:27:33',NULL,NULL,1,11,10,5,1),(12,'2018-09-18 09:29:43','2018-09-18 09:29:43',NULL,NULL,1,11,10,3,2);
 /*!40000 ALTER TABLE `activities` ENABLE KEYS */;
 UNLOCK TABLES;
 
@@ -106,7 +107,7 @@ CREATE TABLE `classes` (
 
 LOCK TABLES `classes` WRITE;
 /*!40000 ALTER TABLE `classes` DISABLE KEYS */;
-INSERT INTO `classes` VALUES (1,'2018-08-24 17:11:29','2018-09-14 08:32:37',NULL,'1 A',0,2),(2,'2018-08-24 17:12:43','2018-08-24 17:12:43','2018-08-24 17:17:01','1 A',1,2);
+INSERT INTO `classes` VALUES (1,'2018-08-24 17:11:29','2018-08-24 17:26:35',NULL,'1 A',3,2),(2,'2018-08-24 17:12:43','2018-08-24 17:12:43','2018-08-24 17:17:01','1 A',1,2);
 /*!40000 ALTER TABLE `classes` ENABLE KEYS */;
 UNLOCK TABLES;
 
@@ -158,7 +159,7 @@ CREATE TABLE `departments` (
 
 LOCK TABLES `departments` WRITE;
 /*!40000 ALTER TABLE `departments` DISABLE KEYS */;
-INSERT INTO `departments` VALUES (1,'2018-09-13 16:21:31','2018-09-13 16:30:10',NULL,'LINGUE STRANIERE',NULL),(4,'2018-09-14 07:17:59','2018-09-14 08:24:29',NULL,'MATEMATICA',1);
+INSERT INTO `departments` VALUES (1,'2018-09-13 16:21:31','2018-09-13 16:30:10',NULL,'LINGUE STRANIERE',NULL),(4,'2018-09-18 09:20:14','2018-09-18 09:20:14',NULL,'SOSTEGNO',0);
 /*!40000 ALTER TABLE `departments` ENABLE KEYS */;
 UNLOCK TABLES;
 
@@ -273,9 +274,10 @@ CREATE TABLE `students` (
   `email` varchar(255) DEFAULT NULL,
   `telephone_number` varchar(255) DEFAULT NULL,
   `plain_password` varchar(255) DEFAULT NULL,
+  `class_id` int(10) unsigned DEFAULT NULL,
   PRIMARY KEY (`id`),
   KEY `idx_students_deleted_at` (`deleted_at`)
-) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
 /*!40101 SET character_set_client = @saved_cs_client */;
 
 --
@@ -284,6 +286,7 @@ CREATE TABLE `students` (
 
 LOCK TABLES `students` WRITE;
 /*!40000 ALTER TABLE `students` DISABLE KEYS */;
+INSERT INTO `students` VALUES (1,'2018-09-18 09:12:14','2018-09-18 09:41:15',NULL,'Mario','ROSSI','','','','','',1),(2,'2018-09-18 09:29:07','2018-09-18 09:40:41',NULL,'Francesco','CONTINO','','','','','',1);
 /*!40000 ALTER TABLE `students` ENABLE KEYS */;
 UNLOCK TABLES;
 
@@ -303,7 +306,7 @@ CREATE TABLE `subjects` (
   `department_id` int(10) unsigned DEFAULT NULL,
   PRIMARY KEY (`id`),
   KEY `idx_subjects_deleted_at` (`deleted_at`)
-) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
+) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1;
 /*!40101 SET character_set_client = @saved_cs_client */;
 
 --
@@ -312,7 +315,7 @@ CREATE TABLE `subjects` (
 
 LOCK TABLES `subjects` WRITE;
 /*!40000 ALTER TABLE `subjects` DISABLE KEYS */;
-INSERT INTO `subjects` VALUES (1,'2018-08-24 17:09:21','2018-09-14 07:31:50',NULL,'MATEMATICA',4),(2,'2018-08-24 17:09:35','2018-08-24 17:09:35',NULL,'ITALIANO',0),(3,'2018-08-24 17:09:44','2018-09-14 07:14:36',NULL,'INGLESE',1),(4,'2018-08-24 17:21:29','2018-08-24 17:21:29',NULL,'STORIA DELL\'ARTE',0),(5,'2018-08-24 17:21:44','2018-08-24 17:21:44',NULL,'SCIENZE',0),(6,'2018-08-24 17:21:59','2018-08-24 17:21:59',NULL,'RELIGIONE',0),(7,'2018-08-24 17:22:31','2018-09-13 16:52:35',NULL,'FRANCESE',1),(8,'2018-08-24 17:23:19','2018-08-24 17:23:19',NULL,'STORIA',0),(9,'2018-08-24 17:23:33','2018-08-24 17:23:33',NULL,'TECNOLOGIA',0);
+INSERT INTO `subjects` VALUES (1,'2018-08-24 17:09:21','2018-08-24 17:09:21',NULL,'MATEMATICA',0),(2,'2018-08-24 17:09:35','2018-08-24 17:09:35',NULL,'ITALIANO',0),(3,'2018-08-24 17:09:44','2018-08-24 17:09:44',NULL,'INGLESE',0),(4,'2018-08-24 17:21:29','2018-08-24 17:21:29',NULL,'STORIA DELL\'ARTE',0),(5,'2018-08-24 17:21:44','2018-08-24 17:21:44',NULL,'SCIENZE',0),(6,'2018-08-24 17:21:59','2018-08-24 17:21:59',NULL,'RELIGIONE',0),(7,'2018-08-24 17:22:31','2018-09-13 16:52:35',NULL,'FRANCESE',1),(8,'2018-08-24 17:23:19','2018-08-24 17:23:19',NULL,'STORIA',0),(9,'2018-08-24 17:23:33','2018-08-24 17:23:33',NULL,'TECNOLOGIA',0),(10,'2018-09-18 09:20:52','2018-09-18 09:20:52',NULL,'SOSTEGNO',4);
 /*!40000 ALTER TABLE `subjects` ENABLE KEYS */;
 UNLOCK TABLES;
 
@@ -388,7 +391,7 @@ CREATE TABLE `teachers` (
   `plain_password` varchar(255) DEFAULT NULL,
   PRIMARY KEY (`id`),
   KEY `idx_teachers_deleted_at` (`deleted_at`)
-) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
+) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=latin1;
 /*!40101 SET character_set_client = @saved_cs_client */;
 
 --
@@ -397,7 +400,7 @@ CREATE TABLE `teachers` (
 
 LOCK TABLES `teachers` WRITE;
 /*!40000 ALTER TABLE `teachers` DISABLE KEYS */;
-INSERT INTO `teachers` VALUES (1,'2018-08-24 17:06:38','2018-08-24 17:17:22',NULL,'Amilcare','AGOSTINO','amilcare.agostino','TpbbDZmSdjzOzEcm5797h2TXY/hzYWx0','amilcare.agostino@foo.org','',18,2,0,NULL),(2,'2018-08-24 17:06:58','2018-08-24 17:18:01',NULL,'Assuntina','DONADONI','assuntina.donadoni','Fi28Y8Q76pqz3ggoAuXvMNliew9zYWx0','assuntina.donadoni@foo.org','',18,2,0,NULL),(3,'2018-08-24 17:07:14','2018-08-24 17:18:26',NULL,'Costanza','LUNGA','costanza.lunga','//XInIkvIeMYj0+x9AsabCyA8zVzYWx0','costanza.lunga@foo.org','',18,5,0,NULL),(4,'2018-08-24 17:07:28','2018-08-24 17:24:20',NULL,'Giacomo','DEL BEN','giacomo.delben','TTdp/vYL+NjgJZTErlceSVwCa1lzYWx0','giacomo.delben@foo.org','',18,2,0,NULL),(5,'2018-08-24 17:07:51','2018-08-24 17:23:58',NULL,'Giorgio','ARISTI','giorgio.aristi','bbtj5tK+TSBKd38G/zHK6TUo0JZzYWx0','giorgio.aristi@foo.org','',18,2,0,NULL),(6,'2018-08-24 17:08:12','2018-08-24 17:25:44',NULL,'Vittoria','GIRONI','vittoria.gironi','jS5M30Y9d5JUsyXSfxU1Vz4Tmc1zYWx0','vittoria.gironi@foo.org','',18,2,0,NULL),(7,'2018-08-24 17:08:33','2018-08-24 17:24:41',NULL,'Francesco','DELLE ROSE','francesco.dellerose','9HakZF2Oh1vZy+8J/doqR1Jpr/lzYWx0','francesco.dellerose@foo.org','',18,2,0,NULL),(8,'2018-08-24 17:08:51','2018-08-24 17:26:15',NULL,'Andrea','PETRUZZELLI','andrea.petruzzelli','enbmvOYnUs/2IkttlR90h3oJC9dzYWx0','andrea.petruzzelli@foo.org','',18,2,0,NULL),(9,'2018-08-24 17:09:07','2018-08-24 17:25:13',NULL,'Piero','FRANCESCHINI','piero.franceschini','eGAGAG9etZ+rehwW0A/KRWt/7CFzYWx0','piero.franceschini@foo.org','',18,2,0,NULL);
+INSERT INTO `teachers` VALUES (1,'2018-08-24 17:06:38','2018-08-24 17:17:22',NULL,'Amilcare','AGOSTINO','amilcare.agostino','TpbbDZmSdjzOzEcm5797h2TXY/hzYWx0','amilcare.agostino@foo.org','',18,2,0,NULL),(2,'2018-08-24 17:06:58','2018-08-24 17:18:01',NULL,'Assuntina','DONADONI','assuntina.donadoni','Fi28Y8Q76pqz3ggoAuXvMNliew9zYWx0','assuntina.donadoni@foo.org','',18,2,0,NULL),(3,'2018-08-24 17:07:14','2018-08-24 17:18:26',NULL,'Costanza','LUNGA','costanza.lunga','//XInIkvIeMYj0+x9AsabCyA8zVzYWx0','costanza.lunga@foo.org','',18,5,0,NULL),(4,'2018-08-24 17:07:28','2018-08-24 17:24:20',NULL,'Giacomo','DEL BEN','giacomo.delben','TTdp/vYL+NjgJZTErlceSVwCa1lzYWx0','giacomo.delben@foo.org','',18,2,0,NULL),(5,'2018-08-24 17:07:51','2018-08-24 17:23:58',NULL,'Giorgio','ARISTI','giorgio.aristi','bbtj5tK+TSBKd38G/zHK6TUo0JZzYWx0','giorgio.aristi@foo.org','',18,2,0,NULL),(6,'2018-08-24 17:08:12','2018-08-24 17:25:44',NULL,'Vittoria','GIRONI','vittoria.gironi','jS5M30Y9d5JUsyXSfxU1Vz4Tmc1zYWx0','vittoria.gironi@foo.org','',18,2,0,NULL),(7,'2018-08-24 17:08:33','2018-08-24 17:24:41',NULL,'Francesco','DELLE ROSE','francesco.dellerose','9HakZF2Oh1vZy+8J/doqR1Jpr/lzYWx0','francesco.dellerose@foo.org','',18,2,0,NULL),(8,'2018-08-24 17:08:51','2018-08-24 17:26:15',NULL,'Andrea','PETRUZZELLI','andrea.petruzzelli','enbmvOYnUs/2IkttlR90h3oJC9dzYWx0','andrea.petruzzelli@foo.org','',18,2,0,NULL),(9,'2018-08-24 17:09:07','2018-08-24 17:25:13',NULL,'Piero','FRANCESCHINI','piero.franceschini','eGAGAG9etZ+rehwW0A/KRWt/7CFzYWx0','piero.franceschini@foo.org','',18,2,0,NULL),(10,'2018-09-18 09:20:32','2018-09-18 09:20:32',NULL,'Pierpaolo','ULCINO','','','','',18,0,NULL,''),(11,'2018-09-18 09:27:15','2018-09-18 09:27:15',NULL,'Nicoletta','MARTINO','','','','',18,0,NULL,'');
 /*!40000 ALTER TABLE `teachers` ENABLE KEYS */;
 UNLOCK TABLES;
 
@@ -442,4 +445,4 @@ UNLOCK TABLES;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
 
--- Dump completed on 2018-09-14  8:35:52
+-- Dump completed on 2018-09-18 10:15:07

+ 20 - 10
orm/orm_test.go

@@ -133,10 +133,22 @@ func (t *testSuite) TestGetTeacherAll() {
 
 }
 
+func (t *testSuite) TestGetStudentAll() {
+	student, err := GetStudentAll(map[string]string{"id": "1"})
+	t.Nil(err)
+	if !t.Failed() {
+		t.Equal("Mario", student.(*Student).Name)
+		t.Equal("ROSSI", student.(*Student).Surname)
+
+		t.Equal("1 A", student.(*Student).Class.Name)
+	}
+
+}
+
 func (t *testSuite) TestGetTeachers() {
 	teachers, err := GetTeachers(map[string]string{})
 	t.Nil(err)
-	t.Equal(9, len(teachers.([]*Teacher)))
+	t.Equal(11, len(teachers.([]*Teacher)))
 
 	teacher := teachers.([]*Teacher)[0]
 	classes, err := teacher.GetClasses()
@@ -151,7 +163,7 @@ func (t *testSuite) TestGetTeachers() {
 func (t *testSuite) TestGetTeachersAll() {
 	teachers, err := GetTeachersAll(map[string]string{})
 	t.Nil(err)
-	t.Equal(9, len(teachers.([]*Teacher)))
+	t.Equal(11, len(teachers.([]*Teacher)))
 
 	t.Equal("1 A", teachers.([]*Teacher)[0].Classes[0].Name)
 	t.Equal("MATEMATICA", teachers.([]*Teacher)[0].Subjects[0].Name)
@@ -192,7 +204,7 @@ func (t *testSuite) TestCreateDeleteTeacher() {
 		_, err = DeleteTeacher(map[string]string{"id": strconv.Itoa(int(teacher.ID))}, nil)
 		t.Nil(err)
 		teachers, _ := GetTeachers(map[string]string{})
-		t.Equal(9, len(teachers.([]*Teacher)))
+		t.Equal(11, len(teachers.([]*Teacher)))
 	}
 }
 
@@ -205,11 +217,11 @@ func (t *testSuite) TestGetDepartments() {
 		department := departments.([]*Department)[0]
 		subjects, err := department.GetSubjects()
 		t.Nil(err)
-		t.Equal(2, len(subjects))
-		t.Equal(2, len(department.Subjects))
+		t.Equal(1, len(subjects))
+		t.Equal(1, len(department.Subjects))
 
 		subject := subjects[0]
-		t.Equal("INGLESE", subject.Name)
+		t.Equal("FRANCESE", subject.Name)
 	}
 }
 
@@ -226,10 +238,8 @@ func (t *testSuite) TestGetDepartmentAll() {
 	department, err := GetDepartmentAll(map[string]string{"id": "1"})
 	t.Nil(err)
 	if !t.Failed() {
-		t.Equal("INGLESE", department.(*Department).Subjects[0].Name)
-		t.Equal("FRANCESE", department.(*Department).Subjects[1].Name)
-		t.Equal("DONADONI", department.(*Department).Teachers[0].Surname)
-		t.Equal("DELLE ROSE", department.(*Department).Teachers[1].Surname)
+		t.Equal("FRANCESE", department.(*Department).Subjects[0].Name)
+		t.Equal("DELLE ROSE", department.(*Department).Teachers[0].Surname)
 	}
 
 }

+ 5 - 5
orm/student.go

@@ -52,13 +52,13 @@ func GetStudentAll(args map[string]string) (interface{}, error) {
 
 	id := args["id"]
 
-	if err := DB().Where("id = ?", id).Find(&student).Error; err != nil {
+	if err := DB().Preload("Class").Where("id = ?", id).Find(&student).Error; err != nil {
 		return nil, err
 	}
 
-	// if err := DB().Preload("Student").Preload("Subject").Preload("Class").Where("student_id=?", id).Find(&student.Activities).Error; err != nil {
-	// 	return nil, err
-	// }
+	if err := DB().Preload("Subject").Preload("Teacher").Preload("Class").Where("student_id=?", id).Find(&student.Activities).Error; err != nil {
+		return nil, err
+	}
 
 	return &student, nil
 }
@@ -73,7 +73,7 @@ func GetStudents(args map[string]string) (interface{}, error) {
 
 func GetStudentsAll(args map[string]string) (interface{}, error) {
 	var students []*Student
-	if err := DB().Order("surname,name").Find(&students).Error; err != nil {
+	if err := DB().Preload("Class").Order("surname,name").Find(&students).Error; err != nil {
 		return nil, err
 	}
 	for _, student := range students {

+ 18 - 1
templates/activities_add_update.html.tpl

@@ -75,6 +75,23 @@
       </select>
     </div>
 
+    <div class="form-group">
+      <label class="control-label" for="student_id">Studente</label>
+      <select name="student_id" class="form-control selectpicker" id="student_id" placeholder="Docente" data-live-search="true" form="form_activities_add_update" title="Seleziona il nome del docente" data-dropup-auto="false">
+	<option value="0"></option>
+  	{{range $student := .Data.AllStudents}}
+	{{if $.Options.Get "update"}}
+  	<option
+	  value="{{$student.ID}}"
+	  {{index $.Data.SelectedStudent $student.ID}}>{{$student.Name}} {{$student.Surname}}
+	</option>
+	{{else}}
+  	<option value="{{$student.ID}}">{{$student.Name}} {{$student.Surname}}</option>
+	{{end}}
+  	{{end}}
+      </select>
+    </div>
+
     <div class="form-group">
       <label class="control-label" for="teacher_id">Docente</label>
       <select name="teacher_id" class="form-control selectpicker" id="teacher_id" placeholder="Docente" data-live-search="true" form="form_activities_add_update" title="Seleziona il nome del docente" data-dropup-auto="false">
@@ -91,7 +108,7 @@
   	{{end}}
       </select>
     </div>
-    
+
     <div class="form-group">
       <label class="control-label" for="hours">Numero di ore</label>
       <input class="form-control" min="0" type="number" name="hours" id="hours" {{if .Options.Get "update"}}value="{{.Data.Activity.Hours}}"{{end}} required>

+ 20 - 0
templates/classes_add_update.html.tpl

@@ -32,6 +32,26 @@
       <input type="text" name="Name" class="form-control" id="class_name" placeholder="Nome" {{if .Options.Get "update"}} value="{{.Data.Class.Name}}" {{end}} required>
     </div>
 
+    <div class="form-group has-feedback">
+      <label class="control-label" for="class_year">Anno</label>
+      <input type="number" min="1" name="Year" class="form-control" id="class_year" placeholder="Annualità" {{if .Options.Get "update"}} value="{{.Data.Class.Year}}" {{end}} required>
+    </div>
+    
+    <div class="form-group has-feedback">
+      <label class="control-label" for="class_name">Sezione</label>
+      <input type="text" name="Section" class="form-control" id="class_section" placeholder="Sezione" {{if .Options.Get "update"}} value="{{.Data.Class.Section}}" {{end}} required>
+    </div>
+
+    <div class="form-group has-feedback">
+      <label class="control-label" for="class_field">Indirizzo</label>
+      <input type="text" name="Field" class="form-control" id="class_field" placeholder="Indirizzo" {{if .Options.Get "update"}} value="{{.Data.Class.Field}}" {{end}} required>
+    </div>
+
+    <div class="form-group has-feedback">
+      <label class="control-label" for="class_alias">Nome alternativo</label>
+      <input type="text" name="Alias" class="form-control" id="class_alias" placeholder="Nome alternativo" {{if .Options.Get "update"}} value="{{.Data.Class.Alias}}" {{end}}>
+    </div>
+
     <div class="form-group">
       <label class="control-label" for="coordinator_id">Coordinatore</label>
       <select name="coordinator_id" class="form-control selectpicker" id="coordinator_id" placeholder="Coordinatore" data-live-search="true" form="form_classes_add_update" title="Seleziona il nome del coordinatore" data-dropup-auto="false">

+ 9 - 2
templates/students.html.tpl

@@ -28,10 +28,17 @@
     {{range $student := .Data}}
     <a class="list-group-item clearfix" href="/students/{{$student.ID}}?{{query "tpl_layout" "base" "tpl_content" "students_show"}}">
       <span class="glyphicon glyphicon-briefcase"></span>
-      {{$student.Name}}
+      {{$student.Surname}} {{$student.Name}}
+      {{if $student.Class}}
       <div class="text-right">
-	<small>optional tag goes here</small>
+	<small>{{$student.Class.Name}}</small>
       </div>
+      {{else}}
+      <div class="text-right">
+	<small>no classe</small>
+      </div>
+
+      {{end}}
     </a>
     {{end}}
   </div>

+ 5 - 5
templates/students_add_update.html.tpl

@@ -28,24 +28,24 @@
   {{end}}
 
   {{if .Options.Get "update"}}
-  <form id="form_students_add_update" action="/students/{{.Data.ID}}/update" method="POST" role="form" data-toggle="validator">
+  <form id="form_students_add_update" action="/students/{{.Data.Student.ID}}/update" method="POST" role="form" data-toggle="validator">
   {{else}}
   <form id="form_students_add_update" action="/students/add/" method="POST" role="form" data-toggle="validator">
   {{end}}
 
     <div class="form-group has-feedback">
       <label class="control-label" for="student_name">Nome</label>
-      <input type="text" name="Name" class="form-control" id="student_name" placeholder="Nome" {{if .Options.Get "update"}} value="{{.Data.Name}}" {{end}} required>
+      <input type="text" name="Name" class="form-control" id="student_name" placeholder="Nome" {{if .Options.Get "update"}} value="{{.Data.Student.Name}}" {{end}} required>
     </div>
 
     <div class="form-group has-feedback">
       <label class="control-label" for="student_surname">Cognome</label>
-      <input type="text" name="Surname" class="form-control" id="student_surname" placeholder="Cognome" {{if .Options.Get "update"}} value="{{.Data.Surname}}" {{end}} required>
+      <input type="text" name="Surname" class="form-control" id="student_surname" placeholder="Cognome" {{if .Options.Get "update"}} value="{{.Data.Student.Surname}}" {{end}} required>
     </div>
 
     <div class="form-group">
       <label class="control-label" for="class_id">Classe</label>
-      <select name="class_id" class="form-control selectpicker" id="class_id" placeholder="Classe" data-live-search="true" form="form_students_add_update" title="Seleziona la classe" data-dropup-auto="false">
+      <select name="class_id" class="form-control selectpicker" id="class_id" placeholder="Classe" data-live-search="true" form="form_students_add_update" title="Seleziona la classe" data-dropup-auto="false" required>
     	<option value="0"></option>
     	{{range $class := .Data.AllClasses}}
     	{{if $.Options.Get "update"}}
@@ -63,7 +63,7 @@
     <div class="form-group">
       <button type="submit" class="btn btn-primary">Salva</button>
       {{if .Options.Get "update"}}
-      <a href="/students/{{.Data.ID}}?{{query "tpl_layout" "base" "tpl_content" "students_show"}}" class="btn btn-default">Annulla</a>
+      <a href="/students/{{.Data.Student.ID}}?{{query "tpl_layout" "base" "tpl_content" "students_show"}}" class="btn btn-default">Annulla</a>
       {{else}}
       <a href="/students?{{query "tpl_layout" "base" "tpl_content" "students"}}" class="btn btn-default">Annulla</a>
       {{end}}

+ 20 - 15
templates/students_show.html.tpl

@@ -3,7 +3,7 @@
 <div class="container">
 
   <ol class="breadcrumb">
-    <li><a href="/students?{{query "tpl_layout" "base" "tpl_content" "students"}}">students</a></li>
+    <li><a href="/students?{{query "tpl_layout" "base" "tpl_content" "students"}}">Studenti</a></li>
     <li class="active"><a href="#">{{.Data.Name}}</a></li>
   </ol>
 
@@ -38,21 +38,26 @@
 
   <div class="row">
     <div class="col-md-12">
-      
-      <h2 class="karmen-relation-header">Docenti dell'allievo</h2>
-      {{if .Data.Teachers}}
-      <div class="list-group" id="materie_list_group">
-    	<a href="/subjects/{{.Data.Subject.ID}}?{{query "tpl_layout" "base" "tpl_content" "subjects_show"}}" class="list-group-item clearfix">
-    	  <span class="glyphicon glyphicon-book"></span>
-    	  {{.Data.Subject.Name}}
-    	</a>
+
+
+      <h2 class="karmen-relation-header">Attività associate all'allievo</h2>
+      <div class="list-group" id="classes_list_group">
+	{{if not .Data.Activities}}
+	<p>All'allievo non è associata alcuna attività
+	  didattica. Clicca <a href="/activities/add?{{query "tpl_content" "activities_add_show" "tpl_layout" "base"}}">qui</a> per creare
+	  una nuova attività didattica da associare all'allievo.</p>
+	{{else}}
+	{{range $activity := .Data.Activities}}
+	<a href="/activities/{{$activity.ID}}?{{query "tpl_layout" "base" "tpl_content" "activities_show"}}" class="list-group-item clearfix">
+	  <span class="glyphicon glyphicon-user"></span>
+	  {{if $activity.Teacher}}{{$activity.Teacher.Surname}} {{$activity.Teacher.Name}}{{else}}no docente{{end}}
+	  <div class="text-right">
+	    <small>{{if $activity.Class}}{{$activity.Class.Name}}{{else}}no classe{{end}}  {{if $activity.Subject}}{{$activity.Subject.Name}}{{else}}no materia{{end}} {{$activity.Hours}}h</small>
+	  </div>
+	</a>
+	{{end}}
+	{{end}}
       </div>
-      {{else}}
-      <p>All'attività non è associata alcuna materia
-    	didattica. Clicca <a href="/activities/update?{{query "tpl_layout" "base" "tpl_content" "activities_add_update"}}">qui</a> per
-    	modificare questa attività didattica.</p>
-      {{end}}
-    </div>
     
   </div>
 

+ 1 - 1
templates/subjects_add_update.html.tpl

@@ -54,7 +54,7 @@
       {{if .Options.Get "update"}}
       <a href="/subjects/{{.Data.Subject.ID}}?{{query "tpl_layout" "base" "tpl_content" "subjects_show"}}" class="btn btn-default">Annulla</a>
       {{else}}
-      <a href="/subjects/?{{query "tpl_layout" "base" "tpl_content" "subjects"}}" class="btn btn-default">Annulla</a>
+      <a href="/subjects?{{query "tpl_layout" "base" "tpl_content" "subjects"}}" class="btn btn-default">Annulla</a>
       {{end}}
     </div>