partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 2e2602ede57ea94e79f307651bb39ed7ec6b81f9
parent 2a996371e1018961298f1e6c4d6398d90fdb55b6
Author: Felicitus <felicitus@felicitus.org>
Date:   Wed, 15 Jun 2011 14:55:44 +0800

Added automatic building of a minified javascript file.

Diffstat:
M.gitignore | 1+
Abuild.properties | 2++
Mbuild.xml | 85+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mfrontend/index.php | 134++++++++++++-------------------------------------------------------------------
Mfrontend/js/Components/CategoryTree.js | 2+-
Mfrontend/js/Components/Statusbar.js | 2+-
Mfrontend/js/org.jerrymouse.util.locale/locale.js | 6------
Apartkeepr.jsb3.template | 28++++++++++++++++++++++++++++
Autil/classes/ExtJSFile.php | 164+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Autil/gen-jsb3-file.php | 108+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10 files changed, 366 insertions(+), 166 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -5,3 +5,4 @@ .settings .project /tests/reports +partkeepr.jsb3 diff --git a/build.properties b/build.properties @@ -0,0 +1 @@ +extjs.path=3rdparty/ext-4.0.2+ \ No newline at end of file diff --git a/build.xml b/build.xml @@ -1,27 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project name="partkeepr" default="test-setup"> - <target name="test-setup" > - <echo msg="Testing the installation..." /> - - <phpunit haltonfailure="true" codecoverage="false" printsummary="true"> - <batchtest> - <fileset dir="setup/tests/"> - <include name="*Test.php" /> - </fileset> - </batchtest> - <formatter type="plain" usefile="false" /> - </phpunit> - - <echo msg=""/> - - <echo msg=" ***************************"/> - <echo msg=" Setup Test Complete"/> - <echo msg=" ***************************"/> - <echo msg=""/> - <echo msg=" No errors were found."/> - <echo msg=" You may now proceed!"/> - </target> - + <property file="build.properties" /> + <target name="pre-commit"> <jsllint haltonfailure="true"> <fileset dir="frontend"> @@ -30,24 +10,23 @@ </jsllint> </target> + <!-- Cleans the output directories --> <target name="clean"> <delete dir="reports" /> <delete dir="build" /> </target> + <!-- Re-generates the proxies needed by Doctrine2 --> <target name="create-orm-proxies"> <exec command="doctrine orm:generate-proxies" passthru="true"/> </target> - <target name="cruise-control" depends="clean,phpmd,jslint,phpcpd,code-coverage,php-documentor"> - - </target> - + <!-- Builds the frontend, regenerates the proxies and minifies the JS --> <target name="build"> <echo>Copying 3rdparty/extjs - this may take up to a few minutes</echo> <mkdir dir="build/"/> <copy overwrite="false" todir="build/extjs/"> - <fileset dir="3rdparty/ext-4.0.2/"> + <fileset dir="${extjs.path}"> <include name="bootstrap.js"/> <include name="compatibility/ext3-core-compat.js"/> <include name="compatibility/ext3-compat.js"/> @@ -63,14 +42,14 @@ <echo>Copying Ext Statusbar</echo> <copy overwrite="false" todir="build/js/Ext.ux/"> - <fileset dir="3rdparty/ext-4.0.2/examples/ux"> + <fileset dir="${extjs.path}/examples/ux"> <include name="statusbar/**"/> </fileset> </copy> <echo>Copying Ext.tab.TabCloseMenu</echo> <copy overwrite="false" todir="build/js/Ext.ux/"> - <fileset dir="3rdparty/ext-4.0.2/examples/ux"> + <fileset dir="${extjs.path}/examples/ux"> <include name="TabCloseMenu.js"/> </fileset> </copy> @@ -91,22 +70,16 @@ </copy> <phingcall target="create-orm-proxies"/> + + <phingcall target="jsbuilder"/> </target> - <target name="build.quick"> - - <echo>Copying JS frontend</echo> - <copy overwrite="true" todir="build/"> - <fileset dir="frontend"> - <include name="js/**"/> - <include name="css/**"/> - <include name="index.html"/> - <include name="service.php"/> - <include name="image.php"/> - <include name="upload.php"/> - </fileset> - </copy> - </target> + + <!-- Builds the jsb3 file and build the minified JS files --> + <target name="jsbuilder"> + <exec command="php util/gen-jsb3-file.php ./frontend/ ${extjs.path}"/> + <exec command="${extjs.path}/jsbuilder/JSBuilder.sh --projectFile ${project.basedir}/partkeepr.jsb3 --deployDir ${project.basedir}/build/js" passthru="true"/> + </target> <!-- Checks all JavaScript files for common mistakes. Requires JSLint from http://www.javascriptlint.com --> <target name="jslint"> @@ -199,4 +172,30 @@ <phpunitreport infile="reports/phpunit/testsuites.xml" format="frames" todir="reports/phpunit"/> </target> + + <target name="test-setup" > + <echo msg="Testing the installation..." /> + + <phpunit haltonfailure="true" codecoverage="false" printsummary="true"> + <batchtest> + <fileset dir="setup/tests/"> + <include name="*Test.php" /> + </fileset> + </batchtest> + <formatter type="plain" usefile="false" /> + </phpunit> + + <echo msg=""/> + + <echo msg=" ***************************"/> + <echo msg=" Setup Test Complete"/> + <echo msg=" ***************************"/> + <echo msg=""/> + <echo msg=" No errors were found."/> + <echo msg=" You may now proceed!"/> + </target> + + <target name="cruise-control" depends="clean,phpmd,jslint,phpcpd,code-coverage,php-documentor"> + + </target> </project> diff --git a/frontend/index.php b/frontend/index.php @@ -1,3 +1,6 @@ +<?php +$debug = true; +?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html> @@ -9,128 +12,29 @@ <!-- Include the ExtJS JavaScript Library --> <script type="text/javascript" src="extjs/bootstrap.js"></script> - <script type="text/javascript" src="extjs/ext-all-debug.js"></script> - - <script type="text/javascript" src="js/Ext.ux/statusbar/StatusBar.js"></script> - <script type="text/javascript" src="js/Ext.ux/SearchField.js"></script> + <?php + // @todo This is ugly, but how to fix? + if ($debug) { + ?> + <script type="text/javascript" src="extjs/ext-all-debug.js"></script> + <script type="text/javascript" src="js/partkeepr-debug.js"></script> + <?php + } else { + ?> + <script type="text/javascript" src="extjs/ext-all.js"></script> + <script type="text/javascript" src="js/partkeepr.js"></script> + <?php + } + ?> + <script type="text/javascript" src="js/org.phpjs.lib/php.default.min.js"></script> <!-- Include the ExtJS CSS Theme --> <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css"/> <link rel="stylesheet" type="text/css" href="js/Ext.ux/statusbar/css/statusbar.css"/> <link rel="stylesheet" type="text/css" href="css/PartKeepr.css"/> - - <script type="text/javascript" src="js/bugfixes.js"></script> - <script type="text/javascript" src="js/Util/i18n.js"></script> - - <script type="text/javascript" src="js/org.phpjs.lib/php.default.min.js"></script> - - <script type="text/javascript" src="js/Dialogs/ExceptionWindow.js"></script> - <script type="text/javascript" src="js/Dialogs/FileUploadDialog.js"></script> - - <script type="text/javascript" src="js/Ext.ux/ClearableComboBox.js"></script> - <script type="text/javascript" src="js/Ext.ux/TabCloseMenu.js"></script> - - <script type="text/javascript" src="js/Components/Widgets/CategoryComboBox.js"></script> - <script type="text/javascript" src="js/Components/Widgets/StorageLocationComboBox.js"></script> - <script type="text/javascript" src="js/Components/Widgets/FootprintComboBox.js"></script> - <script type="text/javascript" src="js/Components/Widgets/ManufacturerComboBox.js"></script> - <script type="text/javascript" src="js/Components/Widgets/DistributorComboBox.js"></script> - <script type="text/javascript" src="js/Components/Widgets/PartUnitComboBox.js"></script> - <script type="text/javascript" src="js/Components/Widgets/UnitComboBox.js"></script> - <script type="text/javascript" src="js/Components/Widgets/PartParameterComboBox.js"></script> - <script type="text/javascript" src="js/Components/Widgets/SiUnitField.js"></script> - <script type="text/javascript" src="js/Components/Widgets/SiUnitList.js"></script> - - <script type="text/javascript" src="js/Util/ServiceCall.js"></script> - - <script type="text/javascript" src="js/org.jerrymouse.util.locale/locale.js"></script> - <script type="text/javascript" src="js/org.jerrymouse.util.locale/locales/en_US.js"></script> - <script type="text/javascript" src="js/org.jerrymouse.util.locale/locales/de_DE.js"></script> - - <script type="text/javascript" src="js/PartKeepr.js"></script> - - <script type="text/javascript" src="js/Models/Footprint.js"></script> - <script type="text/javascript" src="js/Models/StorageLocation.js"></script> - <script type="text/javascript" src="js/Models/Distributor.js"></script> - <script type="text/javascript" src="js/Models/Manufacturer.js"></script> - <script type="text/javascript" src="js/Models/ManufacturerICLogo.js"></script> - <script type="text/javascript" src="js/Models/User.js"></script> - <script type="text/javascript" src="js/Models/Category.js"></script> - <script type="text/javascript" src="js/Models/Part.js"></script> - <script type="text/javascript" src="js/Models/PartUnit.js"></script> - <script type="text/javascript" src="js/Models/PartDistributor.js"></script> - <script type="text/javascript" src="js/Models/PartParameter.js"></script> - <script type="text/javascript" src="js/Models/Unit.js"></script> - <script type="text/javascript" src="js/Models/SiPrefix.js"></script> - <script type="text/javascript" src="js/Models/StockEntry.js"></script> - <script type="text/javascript" src="js/Models/PartManufacturer.js"></script> - - <script type="text/javascript" src="js/Models/Message.js"></script> - - <script type="text/javascript" src="js/Dialogs/Auth/LoginDialog.js"></script> - - <script type="text/javascript" src="js/Components/Statusbar.js"></script> - <script type="text/javascript" src="js/Components/MenuBar.js"></script> - <script type="text/javascript" src="js/Components/ConnectionButton.js"></script> - <script type="text/javascript" src="js/Components/TimeDisplay.js"></script> - <script type="text/javascript" src="js/Components/MessageLog.js"></script> - - <script type="text/javascript" src="js/Components/Editor/EditorGrid.js"></script> - <script type="text/javascript" src="js/Components/Editor/EditorComponent.js"></script> - <script type="text/javascript" src="js/Components/Editor/Editor.js"></script> - - <script type="text/javascript" src="js/Components/CategoryStore.js"></script> - <script type="text/javascript" src="js/Components/CategoryTree.js"></script> - - <script type="text/javascript" src="js/Components/Footprint/FootprintGrid.js"></script> - <script type="text/javascript" src="js/Components/Footprint/FootprintEditor.js"></script> - <script type="text/javascript" src="js/Components/Footprint/FootprintEditorComponent.js"></script> - - <script type="text/javascript" src="js/Components/StorageLocation/StorageLocationGrid.js"></script> - <script type="text/javascript" src="js/Components/StorageLocation/StorageLocationEditor.js"></script> - <script type="text/javascript" src="js/Components/StorageLocation/StorageLocationEditorComponent.js"></script> - - <script type="text/javascript" src="js/Components/Manufacturer/ManufacturerGrid.js"></script> - <script type="text/javascript" src="js/Components/Manufacturer/ManufacturerEditor.js"></script> - <script type="text/javascript" src="js/Components/Manufacturer/ManufacturerEditorComponent.js"></script> - - <script type="text/javascript" src="js/Components/Distributor/DistributorGrid.js"></script> - <script type="text/javascript" src="js/Components/Distributor/DistributorEditor.js"></script> - <script type="text/javascript" src="js/Components/Distributor/DistributorEditorComponent.js"></script> - - <script type="text/javascript" src="js/Components/CategoryEditor/CategoryEditorForm.js"></script> - <script type="text/javascript" src="js/Components/CategoryEditor/CategoryEditorWindow.js"></script> - <script type="text/javascript" src="js/Components/CategoryEditor/CategoryEditorTree.js"></script> - - <script type="text/javascript" src="js/Components/User/UserEditor.js"></script> - <script type="text/javascript" src="js/Components/User/UserEditorComponent.js"></script> - <script type="text/javascript" src="js/Components/User/UserGrid.js"></script> - - <script type="text/javascript" src="js/Components/PartUnit/PartUnitEditor.js"></script> - <script type="text/javascript" src="js/Components/PartUnit/PartUnitEditorComponent.js"></script> - <script type="text/javascript" src="js/Components/PartUnit/PartUnitGrid.js"></script> - - <script type="text/javascript" src="js/Components/Unit/UnitEditor.js"></script> - <script type="text/javascript" src="js/Components/Unit/UnitEditorComponent.js"></script> - <script type="text/javascript" src="js/Components/Unit/UnitGrid.js"></script> - - <script type="text/javascript" src="js/Components/Statistics/CurrentStatisticsDialog.js"></script> - - <script type="text/javascript" src="js/Components/Part/PartsManager.js"></script> - <script type="text/javascript" src="js/Components/Part/PartsGrid.js"></script> - <script type="text/javascript" src="js/Components/Part/PartParameterGrid.js"></script> - <script type="text/javascript" src="js/Components/Part/PartDistributorGrid.js"></script> - <script type="text/javascript" src="js/Components/Part/PartManufacturerGrid.js"></script> - <script type="text/javascript" src="js/Components/Part/PartEditorWindow.js"></script> - <script type="text/javascript" src="js/Components/Part/PartEditor.js"></script> - <script type="text/javascript" src="js/Components/Part/PartFilterPanel.js"></script> - <script type="text/javascript" src="js/Components/Part/PartDisplay.js"></script> - <script type="text/javascript" src="js/Components/Part/PartStockWindow.js"></script> - <script type="text/javascript" src="js/Components/Part/PartStockHistory.js"></script> - - </head> + </head> <body> <?php diff --git a/frontend/js/Components/CategoryTree.js b/frontend/js/Components/CategoryTree.js @@ -1,4 +1,4 @@ -PartKeepr.CategoryTree = Ext.define("CategoryTree", { +Ext.define("PartKeepr.CategoryTree", { alias: 'widget.CategoryTree', extend: 'Ext.tree.Panel', displayField: 'name', diff --git a/frontend/js/Components/Statusbar.js b/frontend/js/Components/Statusbar.js @@ -1,5 +1,5 @@ Ext.define('PartKeepr.Statusbar', { - extend: 'Ext.ux.StatusBar', + extend: 'Ext.ux.statusbar.StatusBar', defaultText: i18n("Ready."), defaultIconCls: 'x-status-valid', diff --git a/frontend/js/org.jerrymouse.util.locale/locale.js b/frontend/js/org.jerrymouse.util.locale/locale.js @@ -14,12 +14,6 @@ Ext.setLocale = function (locale) { Ext.jm_locale = locale; - - Ext.ComponentMgr.all.each( function (item) { - if (item.onLocaleChange) { - item.onLocaleChange(item); - } - }); }; Ext.getLocale = function () { diff --git a/partkeepr.jsb3.template b/partkeepr.jsb3.template @@ -0,0 +1,27 @@ +{ + "projectName": "PartKeepr", + "packages": [{ + "name": "PartKeepr", + "id": "partkeepr", + "files": [ + {{FILES}} + ] + }], + "builds": [ + { + "name": "All", + "target": "partkeepr.js", + "compress": true, + "packages": [ + "partkeepr" + ] + }, + { + "name": "Debug", + "target": "partkeepr-debug.js", + "compress": false, + "packages": [ + "partkeepr" + ] + }] +}+ \ No newline at end of file diff --git a/util/classes/ExtJSFile.php b/util/classes/ExtJSFile.php @@ -0,0 +1,163 @@ +<?php + +class ExtJSFile { + /** + * The source code + * @var string + */ + private $source; + + /** + * Holds the class name + * @var string + */ + private $className; + + /** + * Holds all classes this class requires + * @var array + */ + private $requires = array(); + + /** + * Holds the filename + * @var string + */ + private $filename; + + /** + * Holds all classes which have a dependency to this class + * @var array + */ + private $childs = array(); + + /** + * Constructs a new ExtJSFile class. + * + * @param string $file The source file + */ + public function __construct ($file) { + $this->source = file_get_contents($file); + + if ($this->parseExtendDirective() != "") { + $this->requires[] = $this->parseExtendDirective(); + } + + $this->className = $this->parseClassName(); + + if ($this->requiresPartKeeprBase()) { + $this->requires[] = "PartKeepr"; + } + + $this->filename = $file; + + } + + /** + * Adds a child which depends to this class + * @param ExtJSFile $child + */ + public function addChild (ExtJSFile $child) { + $this->childs[] = $child; + } + + /** + * Returns the class names of all requirements for this class + * @return array An array with the requirement class names + */ + public function getRequires () { + return $this->requires; + } + + /** + * Returns the class name for this class + * @return string The class name + */ + public function getClassName () { + if ($this->className == "") { + return "FILE--".$this->getFilename(); + } else { + return $this->className; + } + } + + public function getFilename () { + return $this->filename; + } + + /** + * Parses the source and returns the "extend" directive. + * + * @return string The extend class name + */ + private function parseExtendDirective () { + $pattern = "/extend:\s*[\"|'](.*)[\"|']/"; + + preg_match($pattern, $this->source, $results); + + // Remove the first element, which contains the RegExp + unset($results[0]); + + return array_pop($results); + } + + /** + * Parses the source and returns the class name. + * + * @return string The class name + */ + private function parseClassName () { + $pattern = "/Ext.define\\([\"|'](.*)[\"|']/"; + + preg_match($pattern, $this->source, $results); + + // Remove the first element, which contains the RegExp + unset($results[0]); + + return array_pop($results); + } + + /** + * Checks if the class needs the base PartKeepr class. + * @return boolean True if the class needs the base PartKeepr class, false otherwise + */ + private function requiresPartKeeprBase () { + if (strpos($this->source, "PartKeepr.getRESTProxy") !== false) { + return true; + } + + return false; + } + + /** + * Returns the JSB entries for this class and all sub classes + * @return string The JSB string with this class and all child classes + */ + public function getJSB () { + + $aData = array($this->getJSBEntry()); + + foreach ($this->childs as $child) { + $aData[] = $child->getJSBEntry(); + } + + return implode(",\n", $aData); + } + + /** + * Returns the JSB Entry for the class + */ + private function getJSBEntry () { + $template = '{"path": "[PATH]","name": "[NAME]"}'; + + $path = dirname($this->filename); + $name = basename($this->filename); + + + $template = str_replace("[PATH]", $path."/", $template); + $template = str_replace("[NAME]", $name, $template); + + return $template; + } + +}+ \ No newline at end of file diff --git a/util/gen-jsb3-file.php b/util/gen-jsb3-file.php @@ -0,0 +1,107 @@ +<?php +/* This script generates the partkeepr.jsb3 file. + * + * Usage: gen-jsb3-filelist.php <path> <extjspath> + * + * + * This script finds all JavaScript files, parses their class names and which + * class they extend, and orders it. + * + * We dynamically order the dependencies. + * */ + +// Check if the path argument was given. If not, bail out. +if ($_SERVER["argc"] !== 3) { + echo "Usage: gen-jsb3-filelist.php <path> <extjspath>\n\n"; + exit(-1); +} + +// Extract the path and check if the path is actually a directory +$path = $_SERVER["argv"][1]; + +if (!is_dir($path)) { + echo "Sorry, we can't read the path $path.\n\n"; + exit(-1); +} + +$extjspath = $_SERVER["argv"][2]; + +if (!is_dir($path)) { + echo "Sorry, we can't read the ExtJS path $extjspath.\n\n"; + exit(-1); +} + + +include("classes/ExtJSFile.php"); + +echo "Finding all javascript files in $path...\n\n"; + +$call = 'find '.$path.' -name *.js -type f'; +exec($call, $output); + +/* Add Ext.ux'es from the ExtJS distribution */ +$output[] = $extjspath . "/examples/ux/statusbar/StatusBar.js"; + +// Spit out the number of JS files we've found +echo "Found ".count($output)." JavaScript files\n\n"; + +$records = array(); + + + +/* Generate class objects out of the source files */ +foreach ($output as $file) { + $file = str_replace("./", "", $file); + + $o = new ExtJSFile($file); + + $records[$o->getClassName()] = $o; +} + +// rootList contains all classes which have no dependencies or external dependencies. +$rootList = array(); + +/* Iterate through the array and build the dependency tree */ +foreach ($records as $key => $record) { + $bHasRequires = false; + + foreach ($record->getRequires() as $require) { + if (stripos($require, "Ext.") === false || stripos($require, "Ext.ux") !== false) { + + /* As PartKeepr is an application and not a class (in terms of this builder), we can't find it. Skip. */ + if ($require == "PartKeepr") { + break; + } + + /* If the parser can't find the class, throw an exception */ + if (!array_key_exists($require, $records)) { + throw new \Exception("Fatal: The class in ". $record->getFilename()." requires the class $require, but the required class isn't in the index."); + } + + $records[$require]->addChild($record); + $bHasRequires = true; + } + } + + if (!$bHasRequires) { + /* Hardcoded check for i18n, as it isn't a class but a script, and needs to put in front of everything */ + if ($record->getFilename() == "frontend/js/Util/i18n.js") { + array_unshift($rootList, $record); + } else { + $rootList[] = $record; + } + } + + +} + +$aData = array(); + +foreach ($rootList as $item) { + $aData[] = $item->getJSB(); +} + +$template = file_get_contents(__DIR__."/../partkeepr.jsb3.template"); +$template = str_replace("{{FILES}}", implode(",\n", $aData), $template); + +file_put_contents(__DIR__."/../partkeepr.jsb3", $template);+ \ No newline at end of file