From d750a029bb8d6e21ad23a753bae7b7ae05bc1e7e Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Fri, 22 Apr 2011 03:12:09 +0200 Subject: [PATCH 1/9] Add internationalization to jobs controller --- application/controllers/jobs.php | 19 ++++++++++++++++--- application/language/english/jobs_lang.php | 7 +++++++ application/language/german/jobs_lang.php | 7 +++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 application/language/english/jobs_lang.php create mode 100644 application/language/german/jobs_lang.php diff --git a/application/controllers/jobs.php b/application/controllers/jobs.php index ad2f774..35d0f39 100644 --- a/application/controllers/jobs.php +++ b/application/controllers/jobs.php @@ -1,7 +1,20 @@ lang->load(strtolower($this->router->class)); + } + + /** + * Get jobs belonging to projects owned by the user. + */ public function getOwn() { $query = $this->db->order_by('progress', 'desc') ->get_where('jobs', array('started_by' => $this->session->userdata('user_id'))); @@ -14,10 +27,10 @@ class Jobs extends CI_Controller { switch($progress) { case -1: - $progress = "Warte auf Start..."; + $progress = lang('waiting'); break; case 100: - $progress = "Fertig"; + $progress = lang('done'); break; default: $progress = $progress . "%"; diff --git a/application/language/english/jobs_lang.php b/application/language/english/jobs_lang.php new file mode 100644 index 0000000..315cb3f --- /dev/null +++ b/application/language/english/jobs_lang.php @@ -0,0 +1,7 @@ + Date: Fri, 22 Apr 2011 03:19:52 +0200 Subject: [PATCH 2/9] Add server model --- application/models/server.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/application/models/server.php b/application/models/server.php index b4d8570..f612791 100644 --- a/application/models/server.php +++ b/application/models/server.php @@ -37,4 +37,14 @@ class Server extends CI_Model { . ", `last_update`=NOW()" . " WHERE `secret`=".$this->db->escape($secret)); } + + /** + * Get the best suiting server for a new job. + * + * @todo not yet verified. + */ + public function get_best_server() { + return $this->db->limit(1)->order_by('last_update', 'desc')-> + get_where('servers', 'workload <= 2')->row_array(); + } } From 79a2b3bafb8599f3af39344180d5a86108e15f2b Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Fri, 22 Apr 2011 03:24:18 +0200 Subject: [PATCH 3/9] Split job logic into model and controller There was a weird mix between the both of them. --- application/controllers/jobs.php | 22 ++++++++++------------ application/models/job.php | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/application/controllers/jobs.php b/application/controllers/jobs.php index 35d0f39..8d5de28 100644 --- a/application/controllers/jobs.php +++ b/application/controllers/jobs.php @@ -7,6 +7,7 @@ class Jobs extends CI_Controller { */ public function __construct() { parent::__construct(); + $this->load->model('job'); // load language file $this->lang->load(strtolower($this->router->class)); @@ -49,23 +50,20 @@ class Jobs extends CI_Controller { ) )); } - - public function listResultsNotSeen() { - $query = $this->db->order_by('started_at', 'asc') - ->get_where('jobs', array('started_by' => $this->session->userdata('user_id'), 'seen' => '0')); - $count = $query->num_rows(); - $jobs = $query->result_array(); - - for($i=0; $idb->select('name')->get_where('projects', array('id' => $jobs[$i]['project_id']))->row()->name; - } + + /** + * Get a list of results that the owner has not yet seen. + * @todo not yet verified + */ + public function get_unseen_results() { + $results = $this->job->get_unseen_results(); $this->output ->set_content_type('application/json') ->set_output(json_encode( array( - 'count' => $count, - 'jobs' => $jobs + 'count' => count($results), + 'results' => $results ) )); } diff --git a/application/models/job.php b/application/models/job.php index de6d45e..14f7cc8 100644 --- a/application/models/job.php +++ b/application/models/job.php @@ -20,4 +20,19 @@ class Job extends CI_Model { $this->db->escape($progress).$finished_at. " WHERE `id`=". $this->db->escape($job_id)); } + + /** + * Get a list of results that the owner has not yet seen. + */ + public function get_unseen_results() { + $query = $this->db->order_by('started_at', 'asc') + ->get_where('jobs', array('started_by' => $this->session->userdata('user_id'), 'seen' => '0')); + $jobs = $query->result_array(); + + for($i=0; $idb->select('name')->get_where('projects', array('id' => $jobs[$i]['project_id']))->row()->name; + } + + return $jobs; + } } From 06c96140dc2ab56847a2e6a5f955c551943587df Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Fri, 22 Apr 2011 03:44:23 +0200 Subject: [PATCH 4/9] Use a global style scheme Controllers: underscores Models: CamelCase --- application/controllers/jobs.php | 2 +- application/controllers/statusrpc.php | 2 +- application/models/job.php | 2 +- application/models/project.php | 2 +- application/models/server.php | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/application/controllers/jobs.php b/application/controllers/jobs.php index 8d5de28..a21a3d8 100644 --- a/application/controllers/jobs.php +++ b/application/controllers/jobs.php @@ -57,7 +57,7 @@ class Jobs extends CI_Controller { * @todo not yet verified */ public function get_unseen_results() { - $results = $this->job->get_unseen_results(); + $results = $this->job->getUnseenResults(); $this->output ->set_content_type('application/json') ->set_output(json_encode( diff --git a/application/controllers/statusrpc.php b/application/controllers/statusrpc.php index 3696f0b..89fec9b 100644 --- a/application/controllers/statusrpc.php +++ b/application/controllers/statusrpc.php @@ -44,6 +44,6 @@ class Statusrpc extends CI_Controller { die("Unauthorized access."); } - $this->server->update_workload($secret, $workload); + $this->server->updateWorkload($secret, $workload); } } \ No newline at end of file diff --git a/application/models/job.php b/application/models/job.php index 14f7cc8..b41f906 100644 --- a/application/models/job.php +++ b/application/models/job.php @@ -24,7 +24,7 @@ class Job extends CI_Model { /** * Get a list of results that the owner has not yet seen. */ - public function get_unseen_results() { + public function getUnseenResults() { $query = $this->db->order_by('started_at', 'asc') ->get_where('jobs', array('started_by' => $this->session->userdata('user_id'), 'seen' => '0')); $jobs = $query->result_array(); diff --git a/application/models/project.php b/application/models/project.php index d51e3d0..8cac9f4 100644 --- a/application/models/project.php +++ b/application/models/project.php @@ -102,7 +102,7 @@ class Project extends CI_Model { * * @param array $project_id The project to get the configuration from. */ - public function get_configurations($project_id) { + public function getConfigurations($project_id) { $query = $this->db->get_where('configurations', array('project_id' => $project_id)); $configurations = $query->result_array(); diff --git a/application/models/server.php b/application/models/server.php index f612791..811829c 100644 --- a/application/models/server.php +++ b/application/models/server.php @@ -10,7 +10,7 @@ class Server extends CI_Model { * * @return array List of all available servers. */ - public function get_all() { + public function getAll() { return $this->db->get('servers')->result_array(); } @@ -19,7 +19,7 @@ class Server extends CI_Model { * * @return array List of servers that could handle another job. */ - public function get_idle() { + public function getIdle() { return $this->db->get_where('servers', 'workload <= 2')->result_array(); } @@ -32,7 +32,7 @@ class Server extends CI_Model { * @param type $secret The server's secret for basic authentication. * @param type $workload The server's workload. */ - public function update_workload($secret, $workload) { + public function updateWorkload($secret, $workload) { $this->db->query("UPDATE `servers` SET `workload`=".$this->db->escape($workload) . ", `last_update`=NOW()" . " WHERE `secret`=".$this->db->escape($secret)); @@ -43,7 +43,7 @@ class Server extends CI_Model { * * @todo not yet verified. */ - public function get_best_server() { + public function getBestServer() { return $this->db->limit(1)->order_by('last_update', 'desc')-> get_where('servers', 'workload <= 2')->row_array(); } From 1d655b724ada2ca4eb1d072c199773cfffe22c4f Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Fri, 22 Apr 2011 10:50:45 +0200 Subject: [PATCH 5/9] Use count() instead of num_rows() when generating JSON --- application/controllers/jobs.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/application/controllers/jobs.php b/application/controllers/jobs.php index a21a3d8..5f57bfe 100644 --- a/application/controllers/jobs.php +++ b/application/controllers/jobs.php @@ -19,7 +19,6 @@ class Jobs extends CI_Controller { public function getOwn() { $query = $this->db->order_by('progress', 'desc') ->get_where('jobs', array('started_by' => $this->session->userdata('user_id'))); - $count = $query->num_rows(); $jobs = $query->result_array(); for($i=0; $iset_content_type('application/json') ->set_output(json_encode( array( - 'count' => $count, + 'count' => count($jobs), 'jobs' => $jobs ) )); From 8bbc04513ea4fe2aa0c958e69ef19eadd473fbcc Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Fri, 22 Apr 2011 10:54:30 +0200 Subject: [PATCH 6/9] Add state 'failed' to a job --- application/controllers/jobs.php | 3 +++ application/language/english/jobs_lang.php | 1 + application/language/german/jobs_lang.php | 1 + 3 files changed, 5 insertions(+) diff --git a/application/controllers/jobs.php b/application/controllers/jobs.php index 5f57bfe..56e72bb 100644 --- a/application/controllers/jobs.php +++ b/application/controllers/jobs.php @@ -29,6 +29,9 @@ class Jobs extends CI_Controller { case -1: $progress = lang('waiting'); break; + case -2: + $progress = lang('failed'); + break; case 100: $progress = lang('done'); break; diff --git a/application/language/english/jobs_lang.php b/application/language/english/jobs_lang.php index 315cb3f..6ab5ed7 100644 --- a/application/language/english/jobs_lang.php +++ b/application/language/english/jobs_lang.php @@ -2,6 +2,7 @@ $lang['done'] = "Complete"; $lang['waiting'] = "Waiting for start..."; +$lang['failed'] = "Computation failed"; /* End of file projects_lang.php */ /* Location: ./application/language/english/jobs_lang.php */ diff --git a/application/language/german/jobs_lang.php b/application/language/german/jobs_lang.php index 9193508..8239c22 100644 --- a/application/language/german/jobs_lang.php +++ b/application/language/german/jobs_lang.php @@ -2,6 +2,7 @@ $lang['done'] = "Fertig"; $lang['waiting'] = "Warte auf Start..."; +$lang['failed'] = "Fehlgeschlagen"; /* End of file projects_lang.php */ /* Location: ./application/language/german/jobs_lang.php */ From 2b69148b2f0337942d13a0fb94c2c55f2e1851d3 Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Fri, 22 Apr 2011 11:29:47 +0200 Subject: [PATCH 7/9] Shorter translation for "failed" --- application/language/english/jobs_lang.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/language/english/jobs_lang.php b/application/language/english/jobs_lang.php index 6ab5ed7..d747055 100644 --- a/application/language/english/jobs_lang.php +++ b/application/language/english/jobs_lang.php @@ -2,7 +2,7 @@ $lang['done'] = "Complete"; $lang['waiting'] = "Waiting for start..."; -$lang['failed'] = "Computation failed"; +$lang['failed'] = "Failed"; /* End of file projects_lang.php */ /* Location: ./application/language/english/jobs_lang.php */ From 8532a5d278ce43c71f01a3fa8d113995f0cfd0eb Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Fri, 22 Apr 2011 12:34:10 +0200 Subject: [PATCH 8/9] Add sample configs for easier installation --- .htaccess.sample | 17 ++ application/config/config.sample.php | 362 +++++++++++++++++++++++++ application/config/database.sample.php | 62 +++++ 3 files changed, 441 insertions(+) create mode 100644 .htaccess.sample create mode 100644 application/config/config.sample.php create mode 100644 application/config/database.sample.php diff --git a/.htaccess.sample b/.htaccess.sample new file mode 100644 index 0000000..33cdd17 --- /dev/null +++ b/.htaccess.sample @@ -0,0 +1,17 @@ + + RewriteEngine On + + RewriteCond %{REQUEST_URI} ^system.* + RewriteRule ^(.*)$ /index.php?/$1 [L] + + RewriteCond %{REQUEST_URI} ^application.* + RewriteRule ^(.*)$ /index.php?/$1 [L] + + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule ^(.*)$ index.php?/$1 [L] + + + + ErrorDocument 404 /index.php + diff --git a/application/config/config.sample.php b/application/config/config.sample.php new file mode 100644 index 0000000..35e6a32 --- /dev/null +++ b/application/config/config.sample.php @@ -0,0 +1,362 @@ + Date: Fri, 22 Apr 2011 13:16:44 +0200 Subject: [PATCH 9/9] Use the actual project id when requesting it, not the node-path --- application/controllers/projects.php | 2 +- application/views/index.php | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/application/controllers/projects.php b/application/controllers/projects.php index 2735759..b01b4a9 100644 --- a/application/controllers/projects.php +++ b/application/controllers/projects.php @@ -64,7 +64,7 @@ class Projects extends CI_Controller { // ->set_output(json_encode(array('count' => $count, 'projects' => $projects))); } - public function detail($projects, $area, $id) { + public function detail($project_id) { $project = $this->project->get($id); $this->output ->set_content_type('application/json') diff --git a/application/views/index.php b/application/views/index.php index 05eaaa0..7354aab 100644 --- a/application/views/index.php +++ b/application/views/index.php @@ -98,7 +98,7 @@ function logout() { function loadProjectInfo(n) { if(n.isLeaf()){ Ext.Ajax.request({ - url: BASE_URL + 'projects/detail' + n.id, + url: BASE_URL + 'projects/detail/' + n.prjId, method: 'get', success: function ( result, request ) { @@ -107,21 +107,10 @@ function loadProjectInfo(n) { tabPanel.add({ title: 'New Tab ', html: 'Lade Projekt...', - closable:true, - handler: function(){ - alert("foo"); - var data = theResponse.result; - var tpl = new Ext.Template( - '

ID: {id}

', - '

Name: {name}

' - ); - - tpl.overwrite(this.html, data); - } + closable:true }).show(); }, failure: function ( result, request ) { - //Ext.MessageBox.alert("Fehler!", "Das gewünschte Projekt kann nicht geladen werden."); switch(result.status) { case 404: Ext.MessageBox.alert("Fehler", "Das gewünschte Projekt konnte nicht gefunden werden.");