summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlo Landmeter <clandmeter@gmail.com>2011-04-26 15:09:14 +0200
committerCarlo Landmeter <clandmeter@gmail.com>2011-04-26 15:09:14 +0200
commite78d4261c296d20c3cebcd7e4e23431c04afa0a9 (patch)
tree7951171a0cfd9aa0388414a898a55b4b28a5deb7
parent26c15e08742fd6b4a87c46461c075beaa37c0594 (diff)
downloadapk_browser-e78d4261c296d20c3cebcd7e4e23431c04afa0a9.tar.bz2
apk_browser-e78d4261c296d20c3cebcd7e4e23431c04afa0a9.tar.xz
multiple changes
add function: remove all apk nodes add function: format commit url, add commit title from aggregator if possible and use a tooltip modified/add apk fields to reflect new apk_tools
-rw-r--r--apk_browser.install8
-rw-r--r--apk_browser.module156
-rw-r--r--tooltip/tooltip.js36
3 files changed, 190 insertions, 10 deletions
diff --git a/apk_browser.install b/apk_browser.install
index ab74d38..852e3b1 100644
--- a/apk_browser.install
+++ b/apk_browser.install
@@ -157,7 +157,7 @@ function _apk_browser_field_vars() {
'apk_size' => array(
'label' => $t('Size')
),
- 'apk_isize' => array(
+ 'apk_installed_size' => array(
'label' => $t('Installed size')
),
'apk_description' => array(
@@ -173,10 +173,10 @@ function _apk_browser_field_vars() {
'apk_origin' => array(
'label' => $t('Origin')
),
- 'builddate' => array(
+ 'apk_build_time' => array(
'label' => $t('Build date')
),
- 'commit' => array(
+ 'apk_commit' => array(
'label' => $t('Commit')
),
'apk_maintainer' => array(
@@ -186,7 +186,7 @@ function _apk_browser_field_vars() {
'label' => $t('Dependencies'),
'cdl' => '-1'
),
- 'install_if' => array(
+ 'apk_install_if' => array(
'label' => $t('Install if'),
'cdl' => '-1'
)
diff --git a/apk_browser.module b/apk_browser.module
index dc769d3..7a7b87c 100644
--- a/apk_browser.module
+++ b/apk_browser.module
@@ -52,6 +52,13 @@ function apk_browser_menu() {
'page callback' => 'apk_browser_importer',
'access arguments' => array('access apk browser'),
);
+ $items['admin/config/apk_browser/delete/all'] = array(
+ 'title' => 'Delete all packages',
+ 'description' => 'Delete all APK packages',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('apk_browser_delete_all_apk_form'),
+ 'access arguments' => array('access apk browser'),
+ );
return $items;
}
@@ -69,11 +76,35 @@ function apk_browser_settings($form) {
'#type' => 'fieldset',
'#title' => t('APK browser settings'),
);
- $form['settings']['apk_import_debug'] = array(
- '#type' => 'checkbox',
- '#title' => t('Import debugging'),
- '#description' => t('Write import debugging to watchdog'),
- '#default_value' => variable_get('apk_import_debug', '0')
+ $form['settings']['apk_import_delete_all_apk_limit'] = array(
+ '#type' => 'textfield',
+ '#size' => '4',
+ '#title' => t('Node delete batch limit'),
+ '#description' => t('While deleting all packages, we need to limit the batch process. If it times out please lower this value.'),
+ '#default_value' => variable_get('apk_import_delete_all_apk_limit', '20')
+ );
+ $form['settings']['apk_import_commit_url'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Commit URL'),
+ '#description' => t('URL to construct a link to repository browser. Use %commit% to be replaced with the actual commit'),
+ '#default_value' => variable_get('apk_import_commit_url', '')
+ );
+ $feeds = array('0' => t('Disabled'));
+ if (module_exists('aggregator')) {
+ $feeds += db_query("SELECT fid,title FROM {aggregator_feed}")->fetchAllKeyed();
+ $disabled = FALSE;
+ $description = t('When enabled, commit title will be searched in this aggregator feed.');
+ } else {
+ $disabled = TRUE;
+ $description = t('You need to have aggregator enabled and configured to enable this.');
+ }
+ $form['settings']['apk_import_aggregator'] = array(
+ '#type' => 'select',
+ '#title' => t('RSS commit lookup'),
+ '#description' => $description,
+ '#default_value' => variable_get('apk_import_aggregator','0'),
+ '#options' => $feeds,
+ '#disabled' => $disabled,
);
return system_settings_form($form);
}
@@ -293,7 +324,7 @@ function apk_browser_add_apk($package, $arch_tid, $repo_tid) {
$node->apk_size['und'][0]['value'] = $value;
break;
case 'I':
- $node->apk_isize['und'][0]['value'] = $value;
+ $node->apk_installed_size['und'][0]['value'] = $value;
break;
case 'T':
$node->apk_description['und'][0]['value'] = $value;
@@ -304,6 +335,18 @@ function apk_browser_add_apk($package, $arch_tid, $repo_tid) {
case 'L':
$node->apk_license['und'][0]['value'] = $value;
break;
+ case 'o':
+ $node->apk_origin['und'][0]['value'] = $value;
+ break;
+ case 'm':
+ $node->apk_maintainer['und'][0]['value'] = $value;
+ break;
+ case 't':
+ $node->apk_build_time['und'][0]['value'] = $value;
+ break;
+ case 'c':
+ $node->apk_commit['und'][0]['value'] = $value;
+ break;
//setting this will update package with this nid number
case 'update':
$node->revision = '1';
@@ -316,6 +359,13 @@ function apk_browser_add_apk($package, $arch_tid, $repo_tid) {
$node->apk_depends['und'][]['value'] = $depend;
}
break;
+ case 'i':
+ //do not keep old install if.
+ unset($node->apk_install_if['und']);
+ foreach ($value as $installif) {
+ $node->apk_install_if['und'][]['value'] = $installif;
+ }
+ break;
}
}
$node->taxonomy_apk_repo['und'][0]['tid'] = $repo_tid;
@@ -427,3 +477,97 @@ function apk_browser_cleanup() {
//record timestamp so we can run this function based on age
variable_set('apk_browser_cleanup', time());
}
+
+//create an url from the commit, and if we find it in aggregator we add a title
+function apk_browser_commit_url($commit) {
+ $fid = variable_get('apk_import_aggregator','0');
+ if (module_exists('aggregator') && $fid) {
+ if (!empty($commit)) {
+ $commit = '%' . $commit . '%';
+ }
+ $title = db_query("SELECT title FROM {aggregator_item} WHERE link LIKE :commit AND fid = :fid", array(':commit' => $commit, ':fid' => $fid))->fetchField();
+ $href = str_replace('%commit%', $commit, variable_get('apk_import_commit_url', ''));
+ $attributes = ($title) ? array('title' => $title, 'class' => 'with-tooltip') : array();
+ return l($commit, $href, array('attributes' => $attributes));
+ } else {
+ return FALSE;
+ }
+}
+
+function apk_browser_preprocess_node($vars) {
+ if ($vars['node']->type == 'apk') {
+ if (isset($vars['apk_commit']['0']['value'])) {
+ $vars['commit_url'] = apk_browser_commit_url($vars['apk_commit']['0']['value']);
+ }
+ $path = drupal_get_path('module', 'apk_browser');
+ drupal_add_js($path . '/tooltip/tooltip.js');
+ drupal_add_js('jQuery().ready(function(){jQuery(".with-tooltip").simpletooltip();});', 'inline');
+ }
+}
+
+function apk_browser_delete_all_apk_form($form, $form_state) {
+ $form = array();
+ $question = t('Are you sure you want to remove all packages?');
+ $path = 'admin/config/apk_browser';
+ $description = t('This action cannot be undone.');
+ $yes = t('Remove all');
+ $no = t('Cancel');
+ return confirm_form($form, $question, $path, $description, $yes, $no);
+}
+
+function apk_browser_delete_all_apk_form_submit($form, &$form_state) {
+ apk_browser_batch_delete_all_apk();
+}
+
+function apk_browser_batch_delete_all_apk() {
+ //define batch options
+ $batch = array(
+ 'operations' => array(
+ array('apk_browser_delete_all_apk', array()),
+ ),
+ 'finished' => 'apk_browser_batch_delete_all_apk_finished',
+ 'title' => t('Deleting all apks'),
+ 'init_message' => t('Starting deletion of all apks.'),
+ 'progress_message' => t('Processed @current out of @total.'),
+ 'error_message' => t('Batch apk delete has encountered an error.'),
+ );
+ //set the batch
+ batch_set($batch);
+ //Only used when not run from forms api. forwards to admin page after complete.
+ batch_process('admin');
+}
+
+function apk_browser_delete_all_apk(&$context) {
+ //node delete limit depending on php timeout
+ $limit = variable_get('apk_import_delete_all_apk_limit', '20');
+ if (!isset($context['sandbox']['progress'])) {
+ $context['sandbox']['progress'] = 0;
+ $qty = db_query("SELECT nid FROM {node} WHERE type = 'apk'")->rowCount();
+ $context['sandbox']['max'] = ceil($qty / $limit);
+ $context['results']['qty'] = $qty;
+ }
+ //delete X nodes set by limit.
+ $nids = db_query("SELECT nid FROM {node} WHERE type = 'apk' LIMIT :limit", array(':limit' => $limit))->fetchCol();
+ node_delete_multiple($nids);
+ //setting progress to calculate progress and display progress bar.
+ $context['sandbox']['progress']++;
+ $context['message'] = t('Deleting @qty packages', array('@qty' => $context['results']['qty']));
+ //on last run we do not set finished and will end batch
+ if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
+ $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
+ }
+}
+
+function apk_browser_batch_delete_all_apk_finished($success, $results, $operations) {
+ if ($success) {
+ // Here we do something meaningful with the results.
+ $message = $results['qty'] . ' packages deleted.';
+ $message .= theme('item_list', $results);
+ } else {
+ // An error occurred.
+ // $operations contains the operations that remained unprocessed.
+ $error_operation = reset($operations);
+ $message = t('An error occurred while processing %error_operation with arguments: @arguments', array('%error_operation' => $error_operation[0], '@arguments' => print_r($error_operation[1], TRUE)));
+ }
+ drupal_set_message($message);
+}
diff --git a/tooltip/tooltip.js b/tooltip/tooltip.js
new file mode 100644
index 0000000..ba7364b
--- /dev/null
+++ b/tooltip/tooltip.js
@@ -0,0 +1,36 @@
+/**
+*
+* simpleTooltip jQuery plugin, by Marius ILIE
+* visit http://dev.mariusilie.net for details
+*
+**/
+(function($){ $.fn.simpletooltip = function(){
+ return this.each(function() {
+ var text = $(this).attr("title");
+ $(this).attr("title", "");
+ if(text != undefined) {
+ $(this).hover(function(e){
+ var tipX = e.pageX + 12;
+ var tipY = e.pageY + 12;
+ $(this).attr("title", "");
+ $("body").append("<div id='simpleTooltip' style='position: absolute; z-index: 100; display: none;'>" + text + "</div>");
+ if($.browser.msie) var tipWidth = $("#simpleTooltip").outerWidth(true)
+ else var tipWidth = $("#simpleTooltip").width()
+ $("#simpleTooltip").width(tipWidth);
+ $("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
+ }, function(){
+ $("#simpleTooltip").remove();
+ $(this).attr("title", text);
+ });
+ $(this).mousemove(function(e){
+ var tipX = e.pageX + 12;
+ var tipY = e.pageY + 12;
+ var tipWidth = $("#simpleTooltip").outerWidth(true);
+ var tipHeight = $("#simpleTooltip").outerHeight(true);
+ if(tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
+ if($(window).height()+$(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
+ $("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
+ });
+ }
+ });
+}})(jQuery); \ No newline at end of file