diff --git a/euscanwww/__init__.py b/euscanwww/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/euscanwww/manage.py b/euscanwww/manage.py new file mode 100644 index 0000000..5e78ea9 --- /dev/null +++ b/euscanwww/manage.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python +from django.core.management import execute_manager +try: + import settings # Assumed to be in the same directory. +except ImportError: + import sys + sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) + sys.exit(1) + +if __name__ == "__main__": + execute_manager(settings) diff --git a/euscanwww/settings.py b/euscanwww/settings.py new file mode 100644 index 0000000..81a9c57 --- /dev/null +++ b/euscanwww/settings.py @@ -0,0 +1,96 @@ +# Django settings for euscanwww project. + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +ADMINS = ( + # ('Your Name', 'your_email@domain.com'), +) + +MANAGERS = ADMINS + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. + 'NAME': '', # Or path to database file if using sqlite3. + 'USER': '', # Not used with sqlite3. + 'PASSWORD': '', # Not used with sqlite3. + 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. + 'PORT': '', # Set to empty string for default. Not used with sqlite3. + } +} + +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# On Unix systems, a value of None will cause Django to use the same +# timezone as the operating system. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = 'America/Chicago' + +# Language code for this installation. All choices can be found here: +# http://www.i18nguy.com/unicode/language-identifiers.html +LANGUAGE_CODE = 'en-us' + +SITE_ID = 1 + +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = True + +# If you set this to False, Django will not format dates, numbers and +# calendars according to the current locale +USE_L10N = True + +# Absolute filesystem path to the directory that will hold user-uploaded files. +# Example: "/home/media/media.lawrence.com/" +MEDIA_ROOT = '' + +# URL that handles the media served from MEDIA_ROOT. Make sure to use a +# trailing slash if there is a path component (optional in other cases). +# Examples: "http://media.lawrence.com", "http://example.com/media/" +MEDIA_URL = '' + +# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a +# trailing slash. +# Examples: "http://foo.com/media/", "/media/". +ADMIN_MEDIA_PREFIX = '/media/' + +# Make this unique, and don't share it with anybody. +SECRET_KEY = 'h!@c5^bi%emv1malwhk(txwqo1(uxyzvp6@+^gn4zyyr2pu*1c' + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', +# 'django.template.loaders.eggs.Loader', +) + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', +) + +ROOT_URLCONF = 'euscanwww.urls' + +TEMPLATE_DIRS = ( + # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. +) + +INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.messages', + # Uncomment the next line to enable the admin: + # 'django.contrib.admin', + # Uncomment the next line to enable admin documentation: + # 'django.contrib.admindocs', +) diff --git a/euscanwww/urls.py b/euscanwww/urls.py new file mode 100644 index 0000000..4e34182 --- /dev/null +++ b/euscanwww/urls.py @@ -0,0 +1,16 @@ +from django.conf.urls.defaults import * + +# Uncomment the next two lines to enable the admin: +# from django.contrib import admin +# admin.autodiscover() + +urlpatterns = patterns('', + # Example: + # (r'^euscanwww/', include('euscanwww.foo.urls')), + + # Uncomment the admin/doc line below to enable admin documentation: + # (r'^admin/doc/', include('django.contrib.admindocs.urls')), + + # Uncomment the next line to enable the admin: + # (r'^admin/', include(admin.site.urls)), +) diff --git a/web/euscan-update b/web/euscan-update deleted file mode 100755 index 23cc78f..0000000 --- a/web/euscan-update +++ /dev/null @@ -1,229 +0,0 @@ -#!/usr/bin/env python - -import subprocess -import portage -import sqlite3 -import sys -import argparse - -def package_id_by_name(c, catpkg): - cat, pkg = catpkg.split('/') - - c.execute('SELECT id FROM packages WHERE category = ? AND package = ?', (cat, pkg)) - - row = c.fetchone() - - if row: - package_id = row[0] - else: - c.execute('INSERT OR IGNORE INTO packages (category, package) VALUES (?,?)', (cat, pkg)) - package_id = c.lastrowid - print '[e] %s/%s' % (cat, pkg) - - return package_id - -def store_package(c, cpv, slot): - catpkg, ver, rev = portage.pkgsplit(cpv) - cat, pkg = catpkg.split('/') - package_id = -1 - - package_id = package_id_by_name(c, catpkg) - - sql = 'INSERT OR IGNORE INTO versions (package_id, slot, revision, version, packaged) VALUES (?, ?, ?, ?, 1)' - c.execute(sql, (package_id, slot, rev, ver)) - - if c.lastrowid: - print '[v] %s:%s' % (cpv, slot) - -def portage_scan(db, package=None): - c = db.cursor() - - cmd = ['eix', '--format', '', '--pure-packages', '-x'] - if package: - cmd.append(package) - - output1 = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] - - cmd = ['eix', '--format', '', '--pure-packages', '-x'] - if package: - cmd.append(package) - output2 = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] - - output1 = output1.split('\n') - output2 = output2.split('\n') - - for i in range(0, len(output1)): - if not output1[i]: - continue - - cpv = output1[i] - slot = output2[i].split(':')[1] - store_package(c, cpv, slot) - - db.commit() - -def herd_id_by_name(cursor, herd): - cursor.execute('SELECT id FROM herds WHERE herd = ?', (herd,)) - - row = cursor.fetchone() - - if row: - herd_id = row[0] - else: - cursor.execute('INSERT INTO herds (herd) VALUES (?)', (herd,)) - herd_id = cursor.lastrowid - print '[h] %s' % (herd) - - return herd_id - -def maintainer_id_by_name(cursor, maintainer): - - cursor.execute('SELECT id FROM maintainers WHERE maintainer = ?', (maintainer,)) - - row = cursor.fetchone() - - if row: - maintainer_id = row[0] - else: - cursor.execute('INSERT INTO maintainers (maintainer) VALUES (?)', (maintainer,)) - maintainer_id = cursor.lastrowid - print '[m] %s' % (maintainer) - - return maintainer_id - - -def store_herd(cursor, catpkg, herd): - if herd == 'no-herd': - return - package_id = package_id_by_name(cursor, catpkg) - herd_id = herd_id_by_name(cursor, herd) - print catpkg, herd - cursor.execute('INSERT OR IGNORE INTO package_herds (herd_id, package_id) VALUES (?, ?)', (herd_id, package_id)) - -def store_maintainer(cursor, catpkg, maintainer): - if maintainer == 'None specified': - return - package_id = package_id_by_name(cursor, catpkg) - maintainer_id = maintainer_id_by_name(cursor, maintainer) - print catpkg, maintainer - cursor.execute('INSERT OR IGNORE INTO package_maintainers (maintainer_id, package_id) VALUES (?, ?)', (maintainer_id, package_id)) - -def metadata_scan_some(c, packages): - cmd = ['epkginfo'] - cmd.extend(packages[:-1]) - output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] - output = output.split('\n\n') - - for infos in output: - infos = infos.split('\n') - - package = packages.pop(0) - - for line in infos: - if line.startswith('Herd:'): - line = line.replace('Herd:', '').strip() - store_herd(c, package, line) - if line.startswith('Maintainer:'): - line = line.replace('Maintainer:', '').strip() - store_maintainer(c, package, line) - -def metadata_scan(db, package=None): - c = db.cursor() - - cmd = ['eix', '--only-names'] - - if package: - cmd.append(package) - output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] - packages = output.split('\n') - - tmp = [] - for package in packages: - tmp.append(package) - if len(tmp) > 10: - metadata_scan_some(c, tmp) - tmp = [] - - metadata_scan_some(c, tmp) - - db.commit() - -def version_id_by_version(cursor, package_id, version): - - cursor.execute('SELECT id, packaged FROM versions WHERE package_id = ? AND version = ?', (package_id, version)) - - row = cursor.fetchone() - - if row: - version_id = row[0] - packaged = row[1] - else: - cursor.execute('INSERT INTO versions (package_id, slot, revision, version, packaged) VALUES (?, ?, ?, ?, 0)', - (package_id, '', 'r0', version)) - version_id = cursor.lastrowid - packaged = 0 - - return version_id, packaged - -def upstream_scan(db, package): - c = db.cursor() - - cmd = ['eix', '--format', '', '--pure-packages'] - if package: - cmd.append(package) - output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] - packages = output.split('\n') - - for package in packages: - if not package.strip(): - continue - catpkg, ver, rev = portage.pkgsplit(package) - - cmd = ['../euscan', package] - output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] - output = output.split('\n') - for line in output: - if not line.startswith('New Upstream Version: '): - continue - line = line.replace('New Upstream Version: ', '').split(' ') - ver = line[0] - urls = line[1:] - - package_id = package_id_by_name(c, catpkg) - version_id, packaged= version_id_by_version(c, package_id, ver) - - if packaged: - continue - - print '[u] %s %s' % (ver, ' '.join(urls)) - - for url in urls: - c.execute('INSERT OR REPLACE INTO upstream_urls (version_id, url) VALUES (?, ?)', (version_id, url)) - db.commit() - - -def main(): - parser = argparse.ArgumentParser(description='Update euscan database.') - parser.add_argument('--skip-portage', action='store_true', help='Skip portage scan.') - parser.add_argument('--skip-metadata', action='store_true', help='Skip metadata scan.') - parser.add_argument('package', nargs='*', help='Only check updates for these packages') - - args = parser.parse_args() - - db = sqlite3.connect('euscan.db') - - if not args.package: - args.package = [None] - - for package in args.package: - if not args.skip_portage: - portage_scan(db, package) - if not args.skip_metadata: - metadata_scan(db, package) - - upstream_scan(db, package) - - db.close() - -if __name__ == '__main__': - main() diff --git a/web/euscan.sql b/web/euscan.sql deleted file mode 100644 index a761d88..0000000 --- a/web/euscan.sql +++ /dev/null @@ -1,54 +0,0 @@ -CREATE TABLE IF NOT EXISTS "packages" ( - "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - "category" TEXT NOT NULL, - "package" TEXT NOT NULL -); - -CREATE UNIQUE INDEX IF NOT EXISTS "packages_catpkg" ON packages (category, package); - -CREATE TABLE IF NOT EXISTS "herds" ( - "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - "herd" TEXT NOT NULL -); - -CREATE INDEX IF NOT EXISTS "herds_herd" ON herds (herd); - -CREATE TABLE IF NOT EXISTS "maintainers" ( - "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - "maintainer" TEXT NOT NULL -); - -CREATE INDEX IF NOT EXISTS "maintainers_maintainer" ON maintainers (maintainer); - -CREATE TABLE IF NOT EXISTS "package_herds" ( - "herd_id" INTEGER NOT NULL, - "package_id" INTEGER NOT NULL, - PRIMARY KEY("herd_id", "package_id") -); - -CREATE TABLE IF NOT EXISTS "package_maintainers" ( - "maintainer_id" INTEGER NOT NULL, - "package_id" INTEGER NOT NULL, - PRIMARY KEY("maintainer_id", "package_id") -); - -CREATE TABLE IF NOT EXISTS "versions" ( - "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - "package_id" INTEGER NOT NULL, - "slot" TEXT NOT NULL, - "revision" TEXT NOT NULL, - "version" TEXT NOT NULL, - "packaged" INTEGER NOT NULL DEFAULT (0) -); - -CREATE INDEX IF NOT EXISTS "versions_packaged" on versions (package_id, packaged); -CREATE UNIQUE INDEX IF NOT EXISTS "versions_version" on versions (package_id, version, slot, revision); - -CREATE TABLE IF NOT EXISTS "upstream_urls" ( - "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - "version_id" INTEGER NOT NULL, - "url" TEXT NOT NULL -); - -CREATE INDEX IF NOT EXISTS "upstream_version" on upstream_urls (version_id); -CREATE UNIQUE INDEX IF NOT EXISTS "upstream_unique_urls" on upstream_urls (version_id, url); \ No newline at end of file diff --git a/web/index.php b/web/index.php deleted file mode 100644 index a591970..0000000 --- a/web/index.php +++ /dev/null @@ -1,209 +0,0 @@ -' ?> - - - euscan - - - - - - -
-query($sql); - - echo ""; - while ($row = $results->fetchArray()) { - $new = $row['versions'] - $row['ebuilds']; - $color = $new == 0 ? 'green' : 'red'; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } - echo "
CategoryEbuildsNew versions
{$row['category']}{$row['ebuilds']}$new
"; -} else if ($act == "herds") { - $sql = "SELECT herd, COUNT(version) as versions, SUM(packaged) as ebuilds"; - $sql.= " FROM herds"; - $sql.= " JOIN package_herds ON herds.id = herd_id"; - $sql.= " JOIN packages ON package_herds.package_id = packages.id"; - $sql.= " JOIN versions ON versions.package_id = packages.id"; - $sql.= " GROUP BY herd"; - - $results = $db->query($sql); - - echo ""; - while ($row = $results->fetchArray()) { - $new = $row['versions'] - $row['ebuilds']; - $color = $new == 0 ? 'green' : 'red'; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } - echo "
HerdEbuildsNew versions
{$row['herd']}{$row['ebuilds']}$new
"; -} else if ($act == "maintainers") { - $sql = "SELECT maintainer, COUNT(version) as versions, SUM(packaged) as ebuilds"; - $sql.= " FROM maintainers"; - $sql.= " JOIN package_maintainers ON maintainers.id = maintainer_id"; - $sql.= " JOIN packages ON package_maintainers.package_id = packages.id"; - $sql.= " JOIN versions ON versions.package_id = packages.id"; - $sql.= " GROUP BY maintainer"; - - $results = $db->query($sql); - - echo ""; - while ($row = $results->fetchArray()) { - $new = $row['versions'] - $row['ebuilds']; - $color = $new == 0 ? 'green' : 'red'; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } - echo "
MaintainerEbuildsNew versions
{$row['maintainer']}{$row['ebuilds']}$new
"; -} else if ($act == "categories") { - $sql = "SELECT category, COUNT(version) as versions, SUM(packaged) as ebuilds"; - $sql.= " FROM packages JOIN versions ON package_id = packages.id"; - $sql.= " GROUP BY category"; - - $results = $db->query($sql); - - echo ""; - while ($row = $results->fetchArray()) { - $new = $row['versions'] - $row['ebuilds']; - $color = $new == 0 ? 'green' : 'red'; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } - echo "
CategoryEbuildsNew versions
{$row['category']}{$row['ebuilds']}$new
"; -} else if ($act == 'packages') { - $db_cat = $db->escapeString($cat); - $db_herd = $db->escapeString($herd); - $db_mtnr = $db->escapeString($mtnr); - - if ($db_cat) { - $sql = "SELECT category, package, COUNT(version) as versions, SUM(packaged) as ebuilds"; - $sql.= " FROM packages JOIN versions ON package_id = packages.id"; - $sql.= " WHERE category = '$db_cat'"; - $sql.= " GROUP BY category, package"; - } else if ($db_herd) { - $sql = "SELECT category, package, COUNT(version) as versions, SUM(packaged) as ebuilds"; - $sql.= " FROM herds"; - $sql.= " JOIN package_herds ON herds.id = herd_id"; - $sql.= " JOIN packages ON package_herds.package_id = packages.id"; - $sql.= " JOIN versions ON versions.package_id = packages.id"; - $sql.= " WHERE herd LIKE '$db_herd'"; - $sql.= " GROUP BY category, package"; - } else if ($db_mtnr) { - $sql = "SELECT category, package, COUNT(version) as versions, SUM(packaged) as ebuilds"; - $sql.= " FROM maintainers"; - $sql.= " JOIN package_maintainers ON maintainers.id = maintainer_id"; - $sql.= " JOIN packages ON package_maintainers.package_id = packages.id"; - $sql.= " JOIN versions ON versions.package_id = packages.id"; - $sql.= " WHERE maintainer LIKE '%$db_mtnr%'"; - $sql.= " GROUP BY category, package"; - } - - if ($sql) { - $results = $db->query($sql); - - echo ""; - while ($row = $results->fetchArray()) { - $new = $row['versions'] - $row['ebuilds']; - $catpkg = "{$row['category']}/{$row['package']}"; - $color = $new == 0 ? 'green' : 'red'; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } - echo "
CategoryEbuildsNew versions
$catpkg{$row['ebuilds']}$new
"; - } -} else if ($act == 'package') { - $pkg = explode("/", $pkg); - - if (count($pkg) == 2) { - $cat = $db->escapeString($pkg[0]); - $pkg = $db->escapeString($pkg[1]); - } else { - $cat = $pkg = ""; - } - - $sql = "SELECT * FROM packages WHERE category = '$cat' AND package = '$pkg'"; - $infos = $db->query($sql); - $infos = $infos->fetchArray(); - - if ($infos) { - echo "

{$infos['category']}/${infos['package']}

"; - - $sql = "SELECT * FROM versions WHERE package_id = ${infos['id']} AND packaged = 1"; - $results = $db->query($sql); - - echo '

Packaged versions:

    '; - while ($version = $results->fetchArray()) { - echo "
  • ${version['version']}-${version['revision']}:${version['slot']}
  • "; - } - - $sql = "SELECT * FROM versions "; - $sql.= "JOIN upstream_urls ON versions.id = version_id "; - $sql.= "WHERE package_id = ${infos['id']} AND packaged = 0"; - $results = $db->query($sql); - - echo '
'; - echo '

Upstream versions:

    '; - - while ($version = $results->fetchArray()) { - echo "
  • ${version['version']} - ${version['url']}
  • "; - } - - echo '
'; - } else { - echo '
Invalid package
'; - } -} - -?> -
- - - - - diff --git a/web/sorttable.js b/web/sorttable.js deleted file mode 100644 index 25bccb2..0000000 --- a/web/sorttable.js +++ /dev/null @@ -1,493 +0,0 @@ -/* - SortTable - version 2 - 7th April 2007 - Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/ - - Instructions: - Download this file - Add to your HTML - Add class="sortable" to any table you'd like to make sortable - Click on the headers to sort - - Thanks to many, many people for contributions and suggestions. - Licenced as X11: http://www.kryogenix.org/code/browser/licence.html - This basically means: do what you want with it. -*/ - - -var stIsIE = /*@cc_on!@*/false; - -sorttable = { - init: function() { - // quit if this function has already been called - if (arguments.callee.done) return; - // flag this function so we don't do the same thing twice - arguments.callee.done = true; - // kill the timer - if (_timer) clearInterval(_timer); - - if (!document.createElement || !document.getElementsByTagName) return; - - sorttable.DATE_RE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/; - - forEach(document.getElementsByTagName('table'), function(table) { - if (table.className.search(/\bsortable\b/) != -1) { - sorttable.makeSortable(table); - } - }); - - }, - - makeSortable: function(table) { - if (table.getElementsByTagName('thead').length == 0) { - // table doesn't have a tHead. Since it should have, create one and - // put the first table row in it. - the = document.createElement('thead'); - the.appendChild(table.rows[0]); - table.insertBefore(the,table.firstChild); - } - // Safari doesn't support table.tHead, sigh - if (table.tHead == null) table.tHead = table.getElementsByTagName('thead')[0]; - - if (table.tHead.rows.length != 1) return; // can't cope with two header rows - - // Sorttable v1 put rows with a class of "sortbottom" at the bottom (as - // "total" rows, for example). This is B&R, since what you're supposed - // to do is put them in a tfoot. So, if there are sortbottom rows, - // for backwards compatibility, move them to tfoot (creating it if needed). - sortbottomrows = []; - for (var i=0; i5' : ' ▴'; - this.appendChild(sortrevind); - return; - } - if (this.className.search(/\bsorttable_sorted_reverse\b/) != -1) { - // if we're already sorted by this column in reverse, just - // re-reverse the table, which is quicker - sorttable.reverse(this.sorttable_tbody); - this.className = this.className.replace('sorttable_sorted_reverse', - 'sorttable_sorted'); - this.removeChild(document.getElementById('sorttable_sortrevind')); - sortfwdind = document.createElement('span'); - sortfwdind.id = "sorttable_sortfwdind"; - sortfwdind.innerHTML = stIsIE ? ' 6' : ' ▾'; - this.appendChild(sortfwdind); - return; - } - - // remove sorttable_sorted classes - theadrow = this.parentNode; - forEach(theadrow.childNodes, function(cell) { - if (cell.nodeType == 1) { // an element - cell.className = cell.className.replace('sorttable_sorted_reverse',''); - cell.className = cell.className.replace('sorttable_sorted',''); - } - }); - sortfwdind = document.getElementById('sorttable_sortfwdind'); - if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); } - sortrevind = document.getElementById('sorttable_sortrevind'); - if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); } - - this.className += ' sorttable_sorted'; - sortfwdind = document.createElement('span'); - sortfwdind.id = "sorttable_sortfwdind"; - sortfwdind.innerHTML = stIsIE ? ' 6' : ' ▾'; - this.appendChild(sortfwdind); - - // build an array to sort. This is a Schwartzian transform thing, - // i.e., we "decorate" each row with the actual sort key, - // sort based on the sort keys, and then put the rows back in order - // which is a lot faster because you only do getInnerText once per row - row_array = []; - col = this.sorttable_columnindex; - rows = this.sorttable_tbody.rows; - for (var j=0; j 12) { - // definitely dd/mm - return sorttable.sort_ddmm; - } else if (second > 12) { - return sorttable.sort_mmdd; - } else { - // looks like a date, but we can't tell which, so assume - // that it's dd/mm (English imperialism!) and keep looking - sortfn = sorttable.sort_ddmm; - } - } - } - } - return sortfn; - }, - - getInnerText: function(node) { - // gets the text we want to use for sorting for a cell. - // strips leading and trailing whitespace. - // this is *not* a generic getInnerText function; it's special to sorttable. - // for example, you can override the cell text with a customkey attribute. - // it also gets .value for fields. - - hasInputs = (typeof node.getElementsByTagName == 'function') && - node.getElementsByTagName('input').length; - - if (node.getAttribute("sorttable_customkey") != null) { - return node.getAttribute("sorttable_customkey"); - } - else if (typeof node.textContent != 'undefined' && !hasInputs) { - return node.textContent.replace(/^\s+|\s+$/g, ''); - } - else if (typeof node.innerText != 'undefined' && !hasInputs) { - return node.innerText.replace(/^\s+|\s+$/g, ''); - } - else if (typeof node.text != 'undefined' && !hasInputs) { - return node.text.replace(/^\s+|\s+$/g, ''); - } - else { - switch (node.nodeType) { - case 3: - if (node.nodeName.toLowerCase() == 'input') { - return node.value.replace(/^\s+|\s+$/g, ''); - } - case 4: - return node.nodeValue.replace(/^\s+|\s+$/g, ''); - break; - case 1: - case 11: - var innerText = ''; - for (var i = 0; i < node.childNodes.length; i++) { - innerText += sorttable.getInnerText(node.childNodes[i]); - } - return innerText.replace(/^\s+|\s+$/g, ''); - break; - default: - return ''; - } - } - }, - - reverse: function(tbody) { - // reverse the rows in a tbody - newrows = []; - for (var i=0; i=0; i--) { - tbody.appendChild(newrows[i]); - } - delete newrows; - }, - - /* sort functions - each sort function takes two parameters, a and b - you are comparing a[0] and b[0] */ - sort_numeric: function(a,b) { - aa = parseFloat(a[0].replace(/[^0-9.-]/g,'')); - if (isNaN(aa)) aa = 0; - bb = parseFloat(b[0].replace(/[^0-9.-]/g,'')); - if (isNaN(bb)) bb = 0; - return aa-bb; - }, - sort_alpha: function(a,b) { - if (a[0]==b[0]) return 0; - if (a[0] 0 ) { - var q = list[i]; list[i] = list[i+1]; list[i+1] = q; - swap = true; - } - } // for - t--; - - if (!swap) break; - - for(var i = t; i > b; --i) { - if ( comp_func(list[i], list[i-1]) < 0 ) { - var q = list[i]; list[i] = list[i-1]; list[i-1] = q; - swap = true; - } - } // for - b++; - - } // while(swap) - } -} - -/* ****************************************************************** - Supporting functions: bundled here to avoid depending on a library - ****************************************************************** */ - -// Dean Edwards/Matthias Miller/John Resig - -/* for Mozilla/Opera9 */ -if (document.addEventListener) { - document.addEventListener("DOMContentLoaded", sorttable.init, false); -} - -/* for Internet Explorer */ -/*@cc_on @*/ -/*@if (@_win32) - document.write("