Index: ConfigController.groovy
===================================================================
--- ConfigController.groovy	(revision 5)
+++ ConfigController.groovy	(revision 6)
@@ -1,13 +1,31 @@
 package com.eneraptor.hci
 
-class ConfigController {
+import groovy.sql.*
+import java.sql.*
+
+class ConfigController {
+	
+	def dataSource
 
     def main = { }
 	
 	def hci = {
-	
+		
+		def db_sql = new Sql(dataSource)
+		
+		def single = db_sql.firstRow("show data_directory")
+		def loca = single.data_directory
+		def partition = new File(loca)
+		def totalSpace = partition.getTotalSpace()
+		def freeSpace  = partition.getFreeSpace()
+		
+		totalSpace = (int)((totalSpace/1024)/1024)
+		freeSpace = (int)((freeSpace/1024)/1024)
+		
+		def percent = 100 - ((int) ((freeSpace/totalSpace)*100))
+		
 		def allDevices = DeviceInfo.list()
-		[conf: InternalConfig, devices: allDevices]		
+		[conf: InternalConfig, devices: allDevices, totalSpace: totalSpace, freeSpace: freeSpace, percent: percent]		
 	}
 	
 	def addDevice = {
@@ -15,16 +33,69 @@
 	
 	def addDeviceSave = {
 		def newDevice = new DeviceInfo(params)
-		if(newDevice.validate()) {
+		if(newDevice.validate() && (params.inputDevice || params.outputDevice)) {
 			newDevice.save()
 			flash['confirms'] = "<p>New device added successfully.</p>"
 			redirect(action:'hci')
 		} else {
 			flash['errors'] = "<p>New device was not saved. Check input data.</p>"
+			if(!params.inputDevice && !params.outputDevice)
+				flash['errors'] += "<p>Device must be capable of making masurements, actions or both. You have selected none.</p>"
 			redirect(action:'addDevice', params: params)
 		}
 	}
 	
+	def deleteHciEntry = {
+		
+		def deviceToBeDeleted = DeviceInfo.findById(params.id)
+		
+		if(deviceToBeDeleted) {
+			deviceToBeDeleted.delete()
+			flash['confirms'] = "<p>Device deleted succesfully.</p>"
+		} else {
+			flash['errors'] = "<p>There was no device deleted.</p><p>There was no device with id ${params.id}.</p>"
+		}
+		redirect(action: 'hci')
+		
+	}
+	
+	def changeHciEntry = {
+		
+		def deviceToBeChanged = DeviceInfo.findById(params.id)
+		if(!deviceToBeChanged) {
+			flash['errors'] = "<p>There is no device with id ${params.id}.</p>"
+			redirect(action: 'hci')
+			return false
+		}
+		deviceToBeChanged.getProperties()
+    }
+	
+	def changeHciEntrySave = {
+		
+		def deviceToBeUpdated = DeviceInfo.findById(params.id)
+		deviceToBeUpdated.properties = params
+		if(deviceToBeUpdated.save()) {
+			flash['confirms'] = "<p>Device updated succesfully.</p>"
+			redirect(action: 'hci')
+		} else {
+			flash['errors'] = "<p>Device was not changed.</p>"
+			redirect(action:'changeHciEntry', params: params)
+		}
+		
+	}
+	
+	def dbInfo = {
+		
+		List databaseInfo = new ArrayList()
+		def db_sql = new Sql(dataSource)
+		db_sql.eachRow "SHOW ALL", {
+			databaseInfo << it.toRowResult()
+		}
+		
+		[databaseInfo: databaseInfo]
+		
+	}
+	
 	def logic = {
 		
 		[conf: InternalConfig]
@@ -53,6 +124,41 @@
 		
 	}
 	
+	def dbExec = {
+		
+		if(params['sqlQuery']) {
+			
+			flash['confirms'] = null
+			flash['errors'] = null
+			
+			def db_sql = new Sql(dataSource)
+			List rows
+			List keys = new ArrayList()
+			boolean wasError = false
+			try {
+				rows = db_sql.rows(params['sqlQuery'])
+				rows[0].each {
+					keys << it.key
+				}
+				flash['confirms'] = "<p>SQL query executed succesfully. Chrck returned rows below.</p>"
+			} catch (SQLException e) {
+				rows = new ArrayList()
+				if(e.getSQLState().equals("02000")) {
+					keys << 'SQL query result'
+					rows << ['SQL query result' : 'No rows were returned.']
+					flash['confirms'] = "<p>SQL query executed succesfully.</p>"
+				} else {
+					rows << e
+					rows << e.getSQLState()
+					wasError = true
+					flash['errors'] = "<p>There was an error while executing the SQL query. Check the report below.</p><p>The query was not executed</p>"
+				}
+			}
+			return [sqlResult: rows, keys: keys, wasError: wasError]
+		}
+		
+	}
+	
 	def getHelp = {
 		[what : params.what]
 	}
