From 4ddf991be35b2677bfc1602eeaf32d96f3449ce1 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Thu, 12 Mar 2020 11:10:11 +0100 Subject: [PATCH] chg: [galaxy:index] Migrated to use the genericElement factory --- app/Controller/GalaxiesController.php | 49 ++++++- app/View/Galaxies/index.ctp | 187 +++++++++++++++----------- app/webroot/js/misp.js | 10 ++ 3 files changed, 163 insertions(+), 83 deletions(-) diff --git a/app/Controller/GalaxiesController.php b/app/Controller/GalaxiesController.php index ce1496c92..f425ef9c1 100644 --- a/app/Controller/GalaxiesController.php +++ b/app/Controller/GalaxiesController.php @@ -18,12 +18,57 @@ class GalaxiesController extends AppController public function index() { + $aclConditions = array(); + // $aclConditions = $this->Galaxy->buildConditions($this->Auth->user()); + $filters = $this->IndexFilter->harvestParameters(array('context', 'value')); + $contextConditions = array(); + if (empty($filters['context'])) { + $filters['context'] = 'all'; + } else { + if ($filters['context'] == 'altered') { // only include galaxies that have modified galaxyCluster + $contextConditions = array( + 'GalaxyCluster.default' => false + ); + } + } + $searchConditions = array(); + if (empty($filters['value'])) { + $filters['value'] = ''; + } else { + $searchall = '%' . strtolower($filters['value']) . '%'; + $searchConditions = array( + 'OR' => array( + 'LOWER(Galaxy.name) LIKE' => $searchall, + 'LOWER(Galaxy.namespace) LIKE' => $searchall, + 'LOWER(Galaxy.description) LIKE' => $searchall, + 'LOWER(Galaxy.kill_chain_order) LIKE' => $searchall, + 'Galaxy.uuid LIKE' => $searchall + ) + ); + } if ($this->_isRest()) { - $galaxies = $this->Galaxy->find('all', array('recursive' => -1)); + $galaxies = $this->Galaxy->find('all', + array( + 'recursive' => -1, + 'conditions' => array( + 'AND' => array($contextConditions, $searchConditions, $aclConditions) + ) + ) + ); return $this->RestResponse->viewData($galaxies, $this->response->type()); } else { + $this->paginate['conditions']['AND'][] = $contextConditions; + $this->paginate['conditions']['AND'][] = $searchConditions; + $this->paginate['conditions']['AND'][] = $aclConditions; + // $this->paginate['contain'] = array('Org', 'Orgc'); $galaxies = $this->paginate(); - $this->set('list', $galaxies); + // foreach ($galaxies as $k => $galaxy) { + // $galaxies[$k] = $this->Galaxy->attachExtendByInfo($this->Auth->user(), $galaxies[$k]); + // $galaxies[$k] = $this->Galaxy->attachExtendFromInfo($this->Auth->user(), $galaxies[$k]); + // } + $this->set('galaxyList', $galaxies); + $this->set('context', $filters['context']); + $this->set('searchall', $filters['value']); } } diff --git a/app/View/Galaxies/index.ctp b/app/View/Galaxies/index.ctp index cf8257ce3..2e622acb0 100644 --- a/app/View/Galaxies/index.ctp +++ b/app/View/Galaxies/index.ctp @@ -1,84 +1,109 @@ -
-

- - - - - - - - - - - - ', - h($item['Galaxy']['id']) - ); - $row .= sprintf( - '', - $this->FontAwesome->findNamespace($item['Galaxy']['icon']), - h($item['Galaxy']['icon']) - ); - $row .= sprintf( - '', - h($item['Galaxy']['name']) - ); - $row .= sprintf( - '', - h($item['Galaxy']['version']) - ); - $row .= sprintf( - '', - h($item['Galaxy']['namespace']) - ); - $row .= sprintf( - '', - h($item['Galaxy']['description']) - ); - $row .= sprintf( - '', - $this->Form->postLink('', array('action' => 'delete', $item['Galaxy']['id']), array('class' => 'fa fa-trash', 'title' => __('Delete'), 'aria-label' => __('Delete')), sprintf(__('Are you sure you want to delete the Galaxy (%s)?'), $item['Galaxy']['name'])), - $this->Html->link('', array('action' => 'view', $item['Galaxy']['id']), array('class' => 'fa fa-eye', 'title' => __('View'), 'aria-label' => __('View'))) - ); - echo $row; - } - ?> -
Paginator->sort('id');?>Paginator->sort('icon', __('Icon'));?>Paginator->sort('name');?>Paginator->sort('version');?>Paginator->sort('namespace', __('Namespace'));?>Paginator->sort('description');?>
%s%s%s%s%s
-

- Paginator->counter(array( - 'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}') - )); - ?> -

- -
'; + echo $this->element('/genericElements/IndexTable/index_table', array( + 'data' => array( + 'data' => $galaxyList, + 'top_bar' => array( + 'children' => array( + array( + 'type' => 'simple', + 'children' => array( + array( + 'active' => $context === 'all', + 'url' => $baseurl . '/galaxies/index/context:all', + 'text' => __('All'), + ), + array( + 'active' => $context === 'altered', + 'url' => $baseurl . '/galaxies/index/context:altered', + 'text' => __('Altered Galaxies'), + ) + ) + ), + array( + 'type' => 'search', + 'button' => __('Filter'), + 'placeholder' => __('Enter value to search'), + 'data' => '', + 'searchKey' => 'value', + 'value' => $searchall + ) + ) + ), + 'fields' => array( + array( + 'name' => __('Galaxy Id'), + 'sort' => 'Galaxy.id', + 'element' => 'links', + 'class' => 'short', + 'data_path' => 'Galaxy.id', + 'url' => $baseurl . '/galaxies/view/%s' + ), + array( + 'name' => __('Icon'), + 'element' => 'icon', + 'class' => 'short', + 'data_path' => 'Galaxy.icon', + ), + array( + 'name' => __('Name'), + 'sort' => 'name', + 'class' => 'short', + 'data_path' => 'Galaxy.name', + ), + array( + 'name' => __('version'), + 'class' => 'short', + 'data_path' => 'Galaxy.version', + ), + array( + 'name' => __('Namespace'), + 'class' => 'short', + 'data_path' => 'Galaxy.namespace', + ), + array( + 'name' => __('Description'), + 'data_path' => 'Galaxy.description', + ) + ), + 'title' => __('Galaxy index'), + 'actions' => array( + array( + 'url' => '/galaxies/view', + 'url_params_data_paths' => array( + 'Galaxy.id' + ), + 'icon' => 'eye', + 'dbclickAction' => true + ), + array( + 'url' => '/galaxies/delete', + 'url_params_data_paths' => array( + 'Galaxy.id' + ), + 'postLink' => true, + 'postLinkConfirm' => __('Are you sure you want to delete the Galaxy?'), + 'icon' => 'trash' + ), + ) + ) + )); + echo ''; echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'galaxies', 'menuItem' => 'index')); ?> + diff --git a/app/webroot/js/misp.js b/app/webroot/js/misp.js index 8e957ef40..cb62609f5 100644 --- a/app/webroot/js/misp.js +++ b/app/webroot/js/misp.js @@ -9,6 +9,11 @@ if (!String.prototype.startsWith) { }; } +function getFAClass(icon) { // TODO: must be generated from the server lib + var fabIcon = ['500px', 'accessible-icon', 'accusoft', 'acquisitions-incorporated', 'adn', 'adobe', 'adversal', 'affiliatetheme', 'airbnb', 'algolia', 'alipay', 'amazon', 'amazon-pay', 'amilia', 'android', 'angellist', 'angrycreative', 'angular', 'app-store', 'app-store-ios', 'apper', 'apple', 'apple-pay', 'artstation', 'asymmetrik', 'atlassian', 'audible', 'autoprefixer', 'avianex', 'aviato', 'aws', 'bandcamp', 'battle-net', 'behance', 'behance-square', 'bimobject', 'bitbucket', 'bitcoin', 'bity', 'black-tie', 'blackberry', 'blogger', 'blogger-b', 'bluetooth', 'bluetooth-b', 'bootstrap', 'btc', 'buffer', 'buromobelexperte', 'canadian-maple-leaf', 'cc-amazon-pay', 'cc-amex', 'cc-apple-pay', 'cc-diners-club', 'cc-discover', 'cc-jcb', 'cc-mastercard', 'cc-paypal', 'cc-stripe', 'cc-visa', 'centercode', 'centos', 'chrome', 'chromecast', 'cloudscale', 'cloudsmith', 'cloudversify', 'codepen', 'codiepie', 'confluence', 'connectdevelop', 'contao', 'cpanel', 'creative-commons', 'creative-commons-by', 'creative-commons-nc', 'creative-commons-nc-eu', 'creative-commons-nc-jp', 'creative-commons-nd', 'creative-commons-pd', 'creative-commons-pd-alt', 'creative-commons-remix', 'creative-commons-sa', 'creative-commons-sampling', 'creative-commons-sampling-plus', 'creative-commons-share', 'creative-commons-zero', 'critical-role', 'css3', 'css3-alt', 'cuttlefish', 'd-and-d', 'd-and-d-beyond', 'dashcube', 'delicious', 'deploydog', 'deskpro', 'dev', 'deviantart', 'dhl', 'diaspora', 'digg', 'digital-ocean', 'discord', 'discourse', 'dochub', 'docker', 'draft2digital', 'dribbble', 'dribbble-square', 'dropbox', 'drupal', 'dyalog', 'earlybirds', 'ebay', 'edge', 'elementor', 'ello', 'ember', 'empire', 'envira', 'erlang', 'ethereum', 'etsy', 'evernote', 'expeditedssl', 'facebook', 'facebook-f', 'facebook-messenger', 'facebook-square', 'fantasy-flight-games', 'fedex', 'fedora', 'figma', 'firefox', 'first-order', 'first-order-alt', 'firstdraft', 'flickr', 'flipboard', 'fly', 'font-awesome', 'font-awesome-alt', 'font-awesome-flag', 'fonticons', 'fonticons-fi', 'fort-awesome', 'fort-awesome-alt', 'forumbee', 'foursquare', 'free-code-camp', 'freebsd', 'fulcrum', 'galactic-republic', 'galactic-senate', 'get-pocket', 'gg', 'gg-circle', 'git', 'git-square', 'github', 'github-alt', 'github-square', 'gitkraken', 'gitlab', 'gitter', 'glide', 'glide-g', 'gofore', 'goodreads', 'goodreads-g', 'google', 'google-drive', 'google-play', 'google-plus', 'google-plus-g', 'google-plus-square', 'google-wallet', 'gratipay', 'grav', 'gripfire', 'grunt', 'gulp', 'hacker-news', 'hacker-news-square', 'hackerrank', 'hips', 'hire-a-helper', 'hooli', 'hornbill', 'hotjar', 'houzz', 'html5', 'hubspot', 'imdb', 'instagram', 'intercom', 'internet-explorer', 'invision', 'ioxhost', 'itch-io', 'itunes', 'itunes-note', 'java', 'jedi-order', 'jenkins', 'jira', 'joget', 'joomla', 'js', 'js-square', 'jsfiddle', 'kaggle', 'keybase', 'keycdn', 'kickstarter', 'kickstarter-k', 'korvue', 'laravel', 'lastfm', 'lastfm-square', 'leanpub', 'less', 'line', 'linkedin', 'linkedin-in', 'linode', 'linux', 'lyft', 'magento', 'mailchimp', 'mandalorian', 'markdown', 'mastodon', 'maxcdn', 'medapps', 'medium', 'medium-m', 'medrt', 'meetup', 'megaport', 'mendeley', 'microsoft', 'mix', 'mixcloud', 'mizuni', 'modx', 'monero', 'napster', 'neos', 'nimblr', 'nintendo-switch', 'node', 'node-js', 'npm', 'ns8', 'nutritionix', 'odnoklassniki', 'odnoklassniki-square', 'old-republic', 'opencart', 'openid', 'opera', 'optin-monster', 'osi', 'page4', 'pagelines', 'palfed', 'patreon', 'paypal', 'penny-arcade', 'periscope', 'phabricator', 'phoenix-framework', 'phoenix-squadron', 'php', 'pied-piper', 'pied-piper-alt', 'pied-piper-hat', 'pied-piper-pp', 'pinterest', 'pinterest-p', 'pinterest-square', 'playstation', 'product-hunt', 'pushed', 'python', 'qq', 'quinscape', 'quora', 'r-project', 'raspberry-pi', 'ravelry', 'react', 'reacteurope', 'readme', 'rebel', 'red-river', 'reddit', 'reddit-alien', 'reddit-square', 'redhat', 'renren', 'replyd', 'researchgate', 'resolving', 'rev', 'rocketchat', 'rockrms', 'safari', 'salesforce', 'sass', 'schlix', 'scribd', 'searchengin', 'sellcast', 'sellsy', 'servicestack', 'shirtsinbulk', 'shopware', 'simplybuilt', 'sistrix', 'sith', 'sketch', 'skyatlas', 'skype', 'slack', 'slack-hash', 'slideshare', 'snapchat', 'snapchat-ghost', 'snapchat-square', 'soundcloud', 'sourcetree', 'speakap', 'speaker-deck', 'spotify', 'squarespace', 'stack-exchange', 'stack-overflow', 'staylinked', 'steam', 'steam-square', 'steam-symbol', 'sticker-mule', 'strava', 'stripe', 'stripe-s', 'studiovinari', 'stumbleupon', 'stumbleupon-circle', 'superpowers', 'supple', 'suse', 'symfony', 'teamspeak', 'telegram', 'telegram-plane', 'tencent-weibo', 'the-red-yeti', 'themeco', 'themeisle', 'think-peaks', 'trade-federation', 'trello', 'tripadvisor', 'tumblr', 'tumblr-square', 'twitch', 'twitter', 'twitter-square', 'typo3', 'uber', 'ubuntu', 'uikit', 'uniregistry', 'untappd', 'ups', 'usb', 'usps', 'ussunnah', 'vaadin', 'viacoin', 'viadeo', 'viadeo-square', 'viber', 'vimeo', 'vimeo-square', 'vimeo-v', 'vine', 'vk', 'vnv', 'vuejs', 'waze', 'weebly', 'weibo', 'weixin', 'whatsapp', 'whatsapp-square', 'whmcs', 'wikipedia-w', 'windows', 'wix', 'wizards-of-the-coast', 'wolf-pack-battalion', 'wordpress', 'wordpress-simple', 'wpbeginner', 'wpexplorer', 'wpforms', 'wpressr', 'xbox', 'xing', 'xing-square', 'y-combinator', 'yahoo', 'yammer', 'yandex', 'yandex-international', 'yarn', 'yelp', 'yoast', 'youtube', 'youtube-square', 'zhihu']; + return fabIcon.indexOf(icon) === -1 ? 'fas' : 'fab'; +} + function stringToRGB(str){ var hash = 0; if (str.length == 0) return hash; @@ -5023,3 +5028,8 @@ function setHomePage() { }, }); } + +function changeLocationFromIndexDblclick(row_index) { + var href = $('.index table tr[data-row-id=\"' + row_index + '\"] .dblclickActionElement').attr('href') + window.location = href; +}