From b5f6782721f0de78d0060eb8d92d368e3a716c11 Mon Sep 17 00:00:00 2001 From: dud3 Date: Fri, 19 Dec 2014 21:47:45 +0000 Subject: [PATCH] [TASK|FEATURE|FIX] Remove Acvive filter items on keywordEntity deletion Closes #43 Releases: 1.2.14 --- app/config/database.php | 236 ++++++------- app/repositories/EloquentEmailsRepository.php | 312 +++++++++--------- app/views/list/emails.blade.php | 178 +++++----- .../scripts/controllers/activeFiltersCtrl.js | 100 +----- .../scripts/controllers/keyWordsListCtrl.js | 9 +- public/scripts/services/errorHandlerSvc.js | 2 + public/scripts/services/helperSvc.js | 60 +++- 7 files changed, 449 insertions(+), 448 deletions(-) diff --git a/app/config/database.php b/app/config/database.php index 48096fb..0594e74 100644 --- a/app/config/database.php +++ b/app/config/database.php @@ -2,123 +2,123 @@ return array( - /* - |-------------------------------------------------------------------------- - | PDO Fetch Style - |-------------------------------------------------------------------------- - | - | By default, database results will be returned as instances of the PHP - | stdClass object; however, you may desire to retrieve records in an - | array format for simplicity. Here you can tweak the fetch style. - | - */ - - 'fetch' => PDO::FETCH_CLASS, - - /* - |-------------------------------------------------------------------------- - | Default Database Connection Name - |-------------------------------------------------------------------------- - | - | Here you may specify which of the database connections below you wish - | to use as your default connection for all database work. Of course - | you may use many connections at once using the Database library. - | - */ - - 'default' => 'mysql', - - /* - |-------------------------------------------------------------------------- - | Database Connections - |-------------------------------------------------------------------------- - | - | Here are each of the database connections setup for your application. - | Of course, examples of configuring each database platform that is - | supported by Laravel is shown below to make development simple. - | - | - | All database work in Laravel is done through the PHP PDO facilities - | so make sure you have the driver for your particular database of - | choice installed on your machine before you begin development. - | - */ - - 'connections' => array( - - 'sqlite' => array( - 'driver' => 'sqlite', - 'database' => __DIR__.'/../database/production.sqlite', - 'prefix' => '', - ), - - 'mysql' => array( - 'driver' => 'mysql', - 'host' => 'localhost', - 'database' => 'e_fwd', - 'username' => 'root', - 'password' => '123123', - 'charset' => 'utf8', - 'collation' => 'utf8_unicode_ci', - 'prefix' => '', - ), - - 'pgsql' => array( - 'driver' => 'pgsql', - 'host' => 'localhost', - 'database' => 'forge', - 'username' => 'forge', - 'password' => '', - 'charset' => 'utf8', - 'prefix' => '', - 'schema' => 'public', - ), - - 'sqlsrv' => array( - 'driver' => 'sqlsrv', - 'host' => 'localhost', - 'database' => 'database', - 'username' => 'root', - 'password' => '', - 'prefix' => '', - ), - - ), - - /* - |-------------------------------------------------------------------------- - | Migration Repository Table - |-------------------------------------------------------------------------- - | - | This table keeps track of all the migrations that have already run for - | your application. Using this information, we can determine which of - | the migrations on disk haven't actually been run in the database. - | - */ - - 'migrations' => 'migrations', - - /* - |-------------------------------------------------------------------------- - | Redis Databases - |-------------------------------------------------------------------------- - | - | Redis is an open source, fast, and advanced key-value store that also - | provides a richer set of commands than a typical key-value systems - | such as APC or Memcached. Laravel makes it easy to dig right in. - | - */ - - 'redis' => array( - - 'cluster' => false, - - 'default' => array( - 'host' => '127.0.0.1', - 'port' => 6379, - 'database' => 0, - ), - - ), + /* + |-------------------------------------------------------------------------- + | PDO Fetch Style + |-------------------------------------------------------------------------- + | + | By default, database results will be returned as instances of the PHP + | stdClass object; however, you may desire to retrieve records in an + | array format for simplicity. Here you can tweak the fetch style. + | + */ + + 'fetch' => PDO::FETCH_CLASS, + + /* + |-------------------------------------------------------------------------- + | Default Database Connection Name + |-------------------------------------------------------------------------- + | + | Here you may specify which of the database connections below you wish + | to use as your default connection for all database work. Of course + | you may use many connections at once using the Database library. + | + */ + + 'default' => 'mysql', + + /* + |-------------------------------------------------------------------------- + | Database Connections + |-------------------------------------------------------------------------- + | + | Here are each of the database connections setup for your application. + | Of course, examples of configuring each database platform that is + | supported by Laravel is shown below to make development simple. + | + | + | All database work in Laravel is done through the PHP PDO facilities + | so make sure you have the driver for your particular database of + | choice installed on your machine before you begin development. + | + */ + + 'connections' => array( + + 'sqlite' => array( + 'driver' => 'sqlite', + 'database' => __DIR__.'/../database/production.sqlite', + 'prefix' => '', + ), + + 'mysql' => array( + 'driver' => 'mysql', + 'host' => 'localhost', + 'database' => 'e_fwd', + 'username' => 'root', + 'password' => '', + 'charset' => 'utf8', + 'collation' => 'utf8_unicode_ci', + 'prefix' => '', + ), + + 'pgsql' => array( + 'driver' => 'pgsql', + 'host' => 'localhost', + 'database' => 'forge', + 'username' => 'forge', + 'password' => '', + 'charset' => 'utf8', + 'prefix' => '', + 'schema' => 'public', + ), + + 'sqlsrv' => array( + 'driver' => 'sqlsrv', + 'host' => 'localhost', + 'database' => 'database', + 'username' => 'root', + 'password' => '', + 'prefix' => '', + ), + + ), + + /* + |-------------------------------------------------------------------------- + | Migration Repository Table + |-------------------------------------------------------------------------- + | + | This table keeps track of all the migrations that have already run for + | your application. Using this information, we can determine which of + | the migrations on disk haven't actually been run in the database. + | + */ + + 'migrations' => 'migrations', + + /* + |-------------------------------------------------------------------------- + | Redis Databases + |-------------------------------------------------------------------------- + | + | Redis is an open source, fast, and advanced key-value store that also + | provides a richer set of commands than a typical key-value systems + | such as APC or Memcached. Laravel makes it easy to dig right in. + | + */ + + 'redis' => array( + + 'cluster' => false, + + 'default' => array( + 'host' => '127.0.0.1', + 'port' => 6379, + 'database' => 0, + ), + + ), ); diff --git a/app/repositories/EloquentEmailsRepository.php b/app/repositories/EloquentEmailsRepository.php index 594791e..530487a 100644 --- a/app/repositories/EloquentEmailsRepository.php +++ b/app/repositories/EloquentEmailsRepository.php @@ -7,217 +7,217 @@ class EloquentEmailsRepository extends EloquentListRepository implements EloquentEmailsRepositoryInterface { - protected $main_sql = null; + protected $main_sql = null; - protected $user; - protected $list; - protected $emails; + protected $user; + protected $list; + protected $emails; - /** - * Main Constructor. - */ - public function __construct() { + /** + * Main Constructor. + */ + public function __construct() { - } + } - /** - * Get all emails. - * @return [type] [description] - */ - public function get_all() { + /** + * Get all emails. + * @return [type] [description] + */ + public function get_all() { - $sql_emails = DB::select( + $sql_emails = DB::select( - "SELECT m.id, m.email_address_id, m.subject, m.body, m.body_html, m.optional_text, m.sender_email, m.reciver_email, - m.fwd_accept, m.sent, - m.x_message_id, m.x_date, m.x_size, m.x_uid, m.x_msgno, m.x_recent, m.x_flagged, m.x_answered, m.x_deleted, - m.x_seen, m.x_draft, m.x_udate, - k_l.keywords + "SELECT m.id, m.email_address_id, m.subject, m.body, m.body_html, m.optional_text, m.sender_email, m.reciver_email, + m.fwd_accept, m.sent, + m.x_message_id, m.x_date, m.x_size, m.x_uid, m.x_msgno, m.x_recent, m.x_flagged, m.x_answered, m.x_deleted, + m.x_seen, m.x_draft, m.x_udate, + k_l.keywords - FROM mails m + FROM mails m - INNER JOIN email_address_list e_a_l - ON e_a_l.id = m.email_address_id + INNER JOIN email_address_list e_a_l + ON e_a_l.id = m.email_address_id - INNER JOIN keywords_list k_l - ON k_l.id = e_a_l.keyword_id + INNER JOIN keywords_list k_l + ON k_l.id = e_a_l.keyword_id - GROUP BY m.x_uid - ORDER BY m.id DESC + GROUP BY m.x_uid + ORDER BY m.id DESC - "); + "); - foreach ($sql_emails as $email) { + foreach ($sql_emails as $email) { - $keywords = []; + $keywords = []; - // trim the string - $keywords = trim($email->keywords); + // trim the string + $keywords = trim($email->keywords); - // decode the JSON string - $keywords = json_decode($email->keywords, true); + // decode the JSON string + $keywords = json_decode($email->keywords, true); - // Search the keywords from the email subject - $subject = explode(" ", $email->subject); + // Search the keywords from the email subject + $subject = explode(" ", $email->subject); - // Basically label around the keywords - // -> found in the email's subject. - foreach ($keywords as $keyword) { + // Basically label around the keywords + // -> found in the email's subject. + foreach ($keywords as $keyword) { - if(false !== $key = array_search($keyword, $subject)) { - $subject[$key] = "" . $subject[$key] . ""; - } + if(false !== $key = array_search($keyword, $subject)) { + $subject[$key] = "" . $subject[$key] . ""; + } - } + } - // Put everything back togather + // Put everything back togather $email->subject = implode(" ", $subject); // Conver to easily readable date format $email->utc_time = date('l, d. F Y h:i:s A', $email->x_udate); - } + } - return $sql_emails; + return $sql_emails; - } + } - /** - * Get email by ID. - * @param [type] $id [description] - * @return [type] [description] - */ - public function get_by_id($id = null) { + /** + * Get email by ID. + * @param [type] $id [description] + * @return [type] [description] + */ + public function get_by_id($id = null) { - } + } - /** - * Find recipients by keyword. - * @param [type] $id [description] - * @return [type] [description] - */ - public function find_recipients_by_keyword($id) { - return email_address_list::where("keyword_id", "=", $id); - } + /** + * Find recipients by keyword. + * @param [type] $id [description] + * @return [type] [description] + */ + public function find_recipients_by_keyword($id) { + return email_address_list::where("keyword_id", "=", $id); + } - /** - * Store a new email. - * @param [type] $data [description] - * @return [type] [description] - */ - public function store($data) { + /** + * Store a new email. + * @param [type] $data [description] + * @return [type] [description] + */ + public function store($data) { - $ret = new stdClass(); + $ret = new stdClass(); - try { + try { - if($data != null) { + if($data != null) { - if(!empty($data)) { + if(!empty($data)) { - foreach ($data as $recipent) { + foreach ($data as $recipent) { - if(self::validate($recipent)) { - $ret->data[] = email_address_list::create($recipent); - $ret->error = false; - } + if(self::validate($recipent)) { + $ret->data[] = email_address_list::create($recipent); + $ret->error = false; + } - } + } - return $ret; + return $ret; - } else { - throw new RuntimeException("Error, The array can not be empty", 0.2); - } + } else { + throw new RuntimeException("Error, The array can not be empty", 0.2); + } - } else { - throw new RuntimeException("Errorm The array can not be null", 0.1); - } + } else { + throw new RuntimeException("Errorm The array can not be null", 0.1); + } - } catch(RuntimeException $e) { + } catch(RuntimeException $e) { - $error = new stdClass(); - $error->message = $e->getMessage(); - $error->code = $e->getCode(); - $error->error = true; + $error = new stdClass(); + $error->message = $e->getMessage(); + $error->code = $e->getCode(); + $error->error = true; - return $error; + return $error; - } + } - } + } - /** - * Updaten the email - * @param [type] $data [description] - * @return [type] [description] - */ - public function update($data) { + /** + * Updaten the email + * @param [type] $data [description] + * @return [type] [description] + */ + public function update($data) { - } + } - /** - * Read the email. - * @param [type] $data [description] - * @return [type] [description] - */ - public function read($data) { + /** + * Read the email. + * @param [type] $data [description] + * @return [type] [description] + */ + public function read($data) { - } + } - /** - * Forward single emails. - * @param [type] $data [description] - * @return [type] [description] - */ - public function forward_single($data) { + /** + * Forward single emails. + * @param [type] $data [description] + * @return [type] [description] + */ + public function forward_single($data) { - } + } - /** - * Forward multiple mails. - * @param [type] $data [description] - * @return [type] [description] - */ - public function forward_multiple($data) { - - } - - /** - * Delete single email. - * @param [type] $id [description] - * @return [type] [description] - */ - public function delete_single($id) { - - } - - /** - * Delete multiple messages at a time. - * @param [type] $data [description] - * @return [type] [description] - */ - public function delete_multiple($data) { + /** + * Forward multiple mails. + * @param [type] $data [description] + * @return [type] [description] + */ + public function forward_multiple($data) { + + } + + /** + * Delete single email. + * @param [type] $id [description] + * @return [type] [description] + */ + public function delete_single($id) { + + } + + /** + * Delete multiple messages at a time. + * @param [type] $data [description] + * @return [type] [description] + */ + public function delete_multiple($data) { - } + } - /** - * Remove recipent from the keywords list. - * @param [type] $id [description] - * @return [type] [description] - */ - public function removeRecipent($id) { - return email_address_list::find($id)->delete(); - } + /** + * Remove recipent from the keywords list. + * @param [type] $id [description] + * @return [type] [description] + */ + public function removeRecipent($id) { + return email_address_list::find($id)->delete(); + } - /** - * Validate email_address_loist. - * @return [type] [description] - */ - public static function validate($data) { - $validator = Validator::make($data, email_address_list::$rules); - if($validator->fails()) return $validator->messages(); - return true; - } + /** + * Validate email_address_loist. + * @return [type] [description] + */ + public static function validate($data) { + $validator = Validator::make($data, email_address_list::$rules); + if($validator->fails()) return $validator->messages(); + return true; + } } diff --git a/app/views/list/emails.blade.php b/app/views/list/emails.blade.php index ea483df..ae4633b 100644 --- a/app/views/list/emails.blade.php +++ b/app/views/list/emails.blade.php @@ -3,104 +3,104 @@
-
- - -
+
+ + +
-
- +
+
- - - - - - - - - - + + + + + + + + + + - + - - - - - - - - + + + + + + + + - + - - + + - - + + - + -
- - - SubjectDateEmails(<* emails.length *>)
+ + + SubjectDateEmails(<* emails.length *>)
-
+ +
diff --git a/public/scripts/controllers/activeFiltersCtrl.js b/public/scripts/controllers/activeFiltersCtrl.js index 113552b..48c57eb 100644 --- a/public/scripts/controllers/activeFiltersCtrl.js +++ b/public/scripts/controllers/activeFiltersCtrl.js @@ -9,8 +9,8 @@ */ angular.module('app.activeFilters') .controller('activeFiltersCtrl', ['$scope', '$rootScope', '$http', '$q', '$compile', '$location', '$sce', '$cookies', '$cookieStore', - 'activeFiltersSvc', '$modal', 'toaster', - function ($scope, $rootScope, $http, $q, $compile, $location, $sce, $cookies, $cookieStore, activeFiltersSvc, $modal, toaster) { + 'activeFiltersSvc', 'HelperSvc', '$modal', 'toaster', + function ($scope, $rootScope, $http, $q, $compile, $location, $sce, $cookies, $cookieStore, activeFiltersSvc, HelperSvc, $modal, toaster) { /** * Holds the filters. @@ -40,18 +40,10 @@ angular.module('app.activeFilters') */ $rootScope.getAllKeywordFilters = function(cache) { - console.log(cache); - console.log(typeof cache); - console.log(isNaN(cache)); - if(typeof cache == 'undefined' || isNaN(cache)) { cache = true; } - console.log(cache); - - - activeFiltersSvc .populateKeywords(cache) .success(function(data){ @@ -78,6 +70,8 @@ angular.module('app.activeFilters') $rootScope.activeFilter.allKeywords = _.uniq($rootScope.activeFilter.allKeywords); + console.log($rootScope.activeFilter.allKeywords); + }).error(function(data){ console.log(data); }); @@ -181,8 +175,6 @@ angular.module('app.activeFilters') // Keywords List $scope.$watch('keyWordsLists', function(){ - // console.log($rootScope.keyWordsLists); - }, true); // Keyword Entity @@ -197,88 +189,30 @@ angular.module('app.activeFilters') // Event listeners can take arguments as param also. // - $scope.$on('keyWordsList-create', function(event, args) { + $scope.$on('keyWordsList-create', function(event, arg) { $rootScope.getRootKeywordFilters(false); $rootScope.getAllKeywordFilters(false); }); - $scope.$on('keyWordsList-delete', function(event, training) { - - }); - - $scope.$on('keyWordsList-single-delete', function(event, training) { + $scope.$on('keyWordsList-delete', function(event, arg) { + + if($rootScope.activeFilter.allKeywords.length > 0) { - }); + $rootScope.activeFilter.rootKeywords.splice(HelperSvc.findInArr($rootScope.activeFilter.rootKeywords, arg._item.keywords[0]) , 1); + var _indexes = HelperSvc.findMulIndexinArr($rootScope.activeFilter.allKeywords, arg._item.keywords); - //------------------------------------------------------------ - // Helper Functions - //------------------------------------------------------------ - // + for (var i = 0; i < _indexes.length; i++) { + console.log(_indexes[i]); + $rootScope.activeFilter.allKeywords.splice(_indexes[i], 1); + }; - /** - * Turn associative array to an array. - * @param {[type]} object [description] - * @return {[type]} [description] - */ - $scope.associative_to_array = function(object) { - var array = []; - for(var item in object){ - if(object[item].hasOwnProperty('keyword')) { - array.push(object[item].keyword); - } else { - array.push(object[item]); - } } - return array; - }; - /** - * Oposite of associative_to_array. - * @param {[type]} array [description] - * @return {[type]} [description] - */ - $scope.array_to_associative = function(array) { - var obj = {}; - for(var i = 0; i < array.length; i++) { - obj[i] = array[i]; // Assign the next element as a value of the object, - // using the current value as key - } - return obj; - }; - - /** - * Stringify the object/associative array. - * @param {[type]} object [description] - * @return {[type]} [description] - */ - $scope.array_stringify = function(object) { - return JSON.stringify(object); - }; + }); - /** - * Validate email. - * @param {[type]} email [description] - * @return {[type]} [description] - */ - $scope.validateEmail = function(email) { - var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; - return re.test(email); - }; + $scope.$on('keyWordsList-single-delete', function(event, training) { - /** - * Find object by it's attribute value. - * @param {[type]} array [description] - * @param {[type]} attr [description] - * @param {[type]} value [description] - * @return {[type]} [description] - */ - $scope.findWithAttr = function(array, attr, value) { - for(var i = 0; i < array.length; i += 1) { - if(array[i][attr] === value) { - return i; - } - } - } + }); }]); \ No newline at end of file diff --git a/public/scripts/controllers/keyWordsListCtrl.js b/public/scripts/controllers/keyWordsListCtrl.js index 174e402..28e26a3 100644 --- a/public/scripts/controllers/keyWordsListCtrl.js +++ b/public/scripts/controllers/keyWordsListCtrl.js @@ -228,6 +228,7 @@ angular.module('app.keyWordsList') }, 300); + // Boradcast to activeFiltersCtrl $rootScope.$broadcast('keyWordsList-create', {}); }).error(function(data){ @@ -254,9 +255,12 @@ angular.module('app.keyWordsList') */ $scope.removeKeywordEntity = function(index, keyWordsLists_id) { + // find item itself. + var _item = HelperSvc.findIntemInArr($rootScope.keyWordsLists, "id", keyWordsLists_id); + // Since we might be filtering and deleting at the same time // check if by unique ID. - var _index = HelperSvc.findWithAttr($rootScope.keyWordsLists, "id", keyWordsLists_id); + var _index = HelperSvc.findIndexWithAttr($rootScope.keyWordsLists, "id", keyWordsLists_id); if(_index != -1) { @@ -266,6 +270,9 @@ angular.module('app.keyWordsList') .removeKeywordEntity(keyWordsLists_id) .success(function(data){ + // Boradcast to activeFiltersCtrl + $rootScope.$broadcast('keyWordsList-delete', {_item}); + }).error(function(data){ toaster.pop('error', "Message", "Something went wrong, please try again."); }); diff --git a/public/scripts/services/errorHandlerSvc.js b/public/scripts/services/errorHandlerSvc.js index 4b1df17..fcb03ec 100644 --- a/public/scripts/services/errorHandlerSvc.js +++ b/public/scripts/services/errorHandlerSvc.js @@ -82,6 +82,8 @@ angular.module('mailTree') build_up_rules: function(elements, rules) { + this.destroyAll(); + var _pass = true; for(var i = 0; i < elements.length; i++) { diff --git a/public/scripts/services/helperSvc.js b/public/scripts/services/helperSvc.js index 147a2dc..8b2336f 100644 --- a/public/scripts/services/helperSvc.js +++ b/public/scripts/services/helperSvc.js @@ -53,6 +53,64 @@ angular.module('mailTree') return re.test(email); }, + /** + * Find multiple indexes in array + * @param {[type]} array [description] + * @param {[type]} values [description] + * @return {[type]} [description] + */ + findMulIndexinArr: function(array, values) { + var indexs = []; + + if(typeof values == 'object') { + values = this.associative_to_array(values); + } + + if(typeof values == 'string') { + values.push(values); + } + + for (var i = array.length - 1; i >= 0; i--) { + for (var j = values.length - 1; j >= 0; j--) { + if(array[i] == values[j]) { + indexs.push(i); + }; + }; + }; + + return indexs; + }, + + /** + * Find element in array. + * @param {[type]} array [description] + * @param {[type]} value [description] + * @return {[type]} [description] + */ + findInArr: function(array, value) { + for (var i = array.length - 1; i >= 0; i--) { + if(array[i] == value) { + return i; + } + } + return -1; + }, + + /** + * Find the elment by attribute value. + * @param {[type]} array [description] + * @param {[type]} attr [description] + * @param {[type]} value [description] + * @return {[type]} [description] + */ + findIntemInArr: function(array, attr, value) { + for(var i = 0; i < array.length; i++) { + if(array[i][attr] == value) { + return array[i]; + } + } + }, + /** * Find object by it's attribute value. * @param {[type]} array [description] @@ -60,7 +118,7 @@ angular.module('mailTree') * @param {[type]} value [description] * @return {[type]} [description] */ - findWithAttr: function(array, attr, value) { + findIndexWithAttr: function(array, attr, value) { for(var i = 0; i < array.length; i += 1) { if(array[i][attr] == value) { return i;