From b0c2fecd42bd8b95f2535a525b035f27aebde287 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 17 Nov 2013 10:17:44 -0800 Subject: WSAT, similar to Microsoft - Web Site Administration Tool and Yii's Gii, will allow as to generate a lot code such as AR classes with the proper relationships... scaffolding... as well as to admin the app configuration and pages configurations in a GUI fashion. --- framework/Wsat/TWsatARGenerator.php | 136 +++++++++++++++++++++ framework/Wsat/TWsatService.php | 42 +++++++ framework/Wsat/TWsatUserManager.php | 18 +++ framework/Wsat/pages/TWsatGenerateAR.page | 23 ++++ framework/Wsat/pages/TWsatGenerateAR.php | 33 +++++ framework/Wsat/pages/TWsatHome.page | 5 + framework/Wsat/pages/TWsatHome.php | 15 +++ framework/Wsat/pages/TWsatLogin.page | 9 ++ framework/Wsat/pages/TWsatLogin.php | 30 +++++ framework/Wsat/pages/TWsatScaffolding.page | 3 + framework/Wsat/pages/TWsatScaffolding.php | 15 +++ framework/Wsat/pages/config.xml | 9 ++ framework/Wsat/pages/layout/TWsatLayout.php | 32 +++++ framework/Wsat/pages/layout/TWsatLayout.tpl | 53 ++++++++ framework/Wsat/themes/.htaccess | 1 + framework/Wsat/themes/PradoSoft/imgs/arrowdown.gif | Bin 0 -> 836 bytes framework/Wsat/themes/PradoSoft/imgs/mantisbg.jpg | Bin 0 -> 4043 bytes framework/Wsat/themes/PradoSoft/imgs/pradologo.gif | Bin 0 -> 3039 bytes framework/Wsat/themes/PradoSoft/style.css | 123 +++++++++++++++++++ 19 files changed, 547 insertions(+) create mode 100644 framework/Wsat/TWsatARGenerator.php create mode 100644 framework/Wsat/TWsatService.php create mode 100644 framework/Wsat/TWsatUserManager.php create mode 100644 framework/Wsat/pages/TWsatGenerateAR.page create mode 100644 framework/Wsat/pages/TWsatGenerateAR.php create mode 100644 framework/Wsat/pages/TWsatHome.page create mode 100644 framework/Wsat/pages/TWsatHome.php create mode 100644 framework/Wsat/pages/TWsatLogin.page create mode 100644 framework/Wsat/pages/TWsatLogin.php create mode 100644 framework/Wsat/pages/TWsatScaffolding.page create mode 100644 framework/Wsat/pages/TWsatScaffolding.php create mode 100644 framework/Wsat/pages/config.xml create mode 100644 framework/Wsat/pages/layout/TWsatLayout.php create mode 100644 framework/Wsat/pages/layout/TWsatLayout.tpl create mode 100644 framework/Wsat/themes/.htaccess create mode 100644 framework/Wsat/themes/PradoSoft/imgs/arrowdown.gif create mode 100644 framework/Wsat/themes/PradoSoft/imgs/mantisbg.jpg create mode 100644 framework/Wsat/themes/PradoSoft/imgs/pradologo.gif create mode 100644 framework/Wsat/themes/PradoSoft/style.css (limited to 'framework/Wsat') diff --git a/framework/Wsat/TWsatARGenerator.php b/framework/Wsat/TWsatARGenerator.php new file mode 100644 index 00000000..7b39fce1 --- /dev/null +++ b/framework/Wsat/TWsatARGenerator.php @@ -0,0 +1,136 @@ +_ar_manager = TActiveRecordManager::getInstance(); + $this->_opnamespace = $_opnamespace; + } + + // + public function generate($tableName, $clasName = '') { + $conn = $this->_ar_manager->getDbConnection(); + $gateway = $this->_ar_manager->getRecordGateway(); + $tableInfo = $gateway->getTableInfo($conn, $tableName); + + if (count($tableInfo->getColumns()) === 0) { + throw new TIOException("Unable to find table or view $tableName in " . $conn->getConnectionString() . "."); + } else { + $properties = array(); + foreach ($tableInfo->getColumns() as $field => $column) + $properties[] = $this->generateProperty($field, $column); + } + + $clasName = empty($clasName) ? $this->_getClassName($tableName) : $clasName; + $class = $this->generateClass($properties, $tableName, $clasName); + $op_file = Prado::getPathOfNamespace($this->_opnamespace); + if (!is_dir($op_file)) { + mkdir($op_file, 0777, true); + } + + $output = $op_file . DIRECTORY_SEPARATOR . $clasName . ".php"; + file_put_contents($output, $class); + } + + public function generateAll() { + foreach ($this->_getAllTableNames() as $tableName) { + $this->generate($tableName); + } + } + +// +//----------------------------------------------------------------------------- + // + private function getDbConnection() { + $con = $this->_ar_manager->getDbConnection(); + $con->Active = true; + return $con; + } + + private function _getAllTableNames() { + $con = $this->getDbConnection(); + $command = $con->createCommand("Show Tables"); + $dataReader = $command->query(); + $dataReader->bindColumn(1, $table); + $tables = array(); + while ($dataReader->read()) { + $tables[] = $table; + } + $con->setActive(false); + return $tables; + } + + private function _getClassName($tableName) { + return ucfirst($tableName); + } + + public function renderAllTablesInformation() { + $conn = $this->_ar_manager->getDbConnection(); + $gateway = $this->_ar_manager->getRecordGateway(); + + foreach ($this->_getAllTableNames() as $table_name) { + echo $table_name . "
"; + + $tableInfo = $gateway->getTableInfo($conn, $table_name); + echo "Table info:" . "
"; + echo "
";
+            var_dump($tableInfo);
+            echo "
"; + } + } + +//----------------------------------------------------------------------------- + + protected function generateProperty($field, $column) { + $prop = ''; + $name = '$' . $field; + + /* TODO use in version 2.0 */ + // $type = $column->getPHPType(); + + $prop .= "\tpublic $name;"; + return $prop; + } + + protected function generateClass($properties, $tablename, $class) { + $props = implode("\n", $properties); + $date = date('Y-m-d h:i:s'); + return << +EOD; + } + +//
+} + +?> diff --git a/framework/Wsat/TWsatService.php b/framework/Wsat/TWsatService.php new file mode 100644 index 00000000..009ad302 --- /dev/null +++ b/framework/Wsat/TWsatService.php @@ -0,0 +1,42 @@ +getApplication()->getMode() === TApplicationMode::Performance + || $this->getApplication()->getMode() === TApplicationMode::Normal) { + throw new TInvalidOperationException("You should not use Prado WSAT in any of the production modes."); + } + if (empty($this->_pass)) { + throw new TConfigurationException("You need to specify the Password attribute."); + } + $this->setDefaultPage("TWsatHome"); + parent::init($config); + } + + public function getBasePath() { + $basePath = Prado::getPathOfNamespace("System.Wsat.pages"); + return realpath($basePath); + } + + public function getPassword() { + return $this->_pass; + } + + public function setPassword($_pass) { + $this->_pass = $_pass; + } + +} + +?> diff --git a/framework/Wsat/TWsatUserManager.php b/framework/Wsat/TWsatUserManager.php new file mode 100644 index 00000000..b9a9eb8b --- /dev/null +++ b/framework/Wsat/TWsatUserManager.php @@ -0,0 +1,18 @@ + diff --git a/framework/Wsat/pages/TWsatGenerateAR.page b/framework/Wsat/pages/TWsatGenerateAR.page new file mode 100644 index 00000000..3905d023 --- /dev/null +++ b/framework/Wsat/pages/TWsatGenerateAR.page @@ -0,0 +1,23 @@ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ + +
+
+ +
diff --git a/framework/Wsat/pages/TWsatGenerateAR.php b/framework/Wsat/pages/TWsatGenerateAR.php new file mode 100644 index 00000000..754cac5c --- /dev/null +++ b/framework/Wsat/pages/TWsatGenerateAR.php @@ -0,0 +1,33 @@ +table_name->Text; + + $ar_generator = new TWsatARGenerator(); + if ($table_name != "*") { + $ar_generator->generate($table_name); + } else { + $ar_generator->generateAll(); + } + } + + public function preview($sender) { + + } + +} + +?> \ No newline at end of file diff --git a/framework/Wsat/pages/TWsatHome.page b/framework/Wsat/pages/TWsatHome.page new file mode 100644 index 00000000..16aa3669 --- /dev/null +++ b/framework/Wsat/pages/TWsatHome.page @@ -0,0 +1,5 @@ + + + +
Application Dir: <%= Prado::getPathOfNamespace('Application') %>
+
diff --git a/framework/Wsat/pages/TWsatHome.php b/framework/Wsat/pages/TWsatHome.php new file mode 100644 index 00000000..3c1358e1 --- /dev/null +++ b/framework/Wsat/pages/TWsatHome.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/framework/Wsat/pages/TWsatLogin.page b/framework/Wsat/pages/TWsatLogin.page new file mode 100644 index 00000000..dada4248 --- /dev/null +++ b/framework/Wsat/pages/TWsatLogin.page @@ -0,0 +1,9 @@ + +
+ + +
+ +
+ +
diff --git a/framework/Wsat/pages/TWsatLogin.php b/framework/Wsat/pages/TWsatLogin.php new file mode 100644 index 00000000..7435d75d --- /dev/null +++ b/framework/Wsat/pages/TWsatLogin.php @@ -0,0 +1,30 @@ +getService()->getPassword(); + $user_pass = $this->password->Text; + + if ($user_pass === $config_pass) { + $this->Session["wsat_password"] = $config_pass; + + $authManager = $this->Application->getModule('auth'); + $url = $authManager->ReturnUrl; + if (empty($url)) { + $url = $this->Service->constructUrl('TWsatHome'); + } + $this->Response->redirect($url); + } else { + echo "user or pass wrong"; + } + } + +} + +?> \ No newline at end of file diff --git a/framework/Wsat/pages/TWsatScaffolding.page b/framework/Wsat/pages/TWsatScaffolding.page new file mode 100644 index 00000000..42f78d09 --- /dev/null +++ b/framework/Wsat/pages/TWsatScaffolding.page @@ -0,0 +1,3 @@ + + Scaffolding will be avaliable in Prado 3.4 + diff --git a/framework/Wsat/pages/TWsatScaffolding.php b/framework/Wsat/pages/TWsatScaffolding.php new file mode 100644 index 00000000..afa00273 --- /dev/null +++ b/framework/Wsat/pages/TWsatScaffolding.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/framework/Wsat/pages/config.xml b/framework/Wsat/pages/config.xml new file mode 100644 index 00000000..832b6cc3 --- /dev/null +++ b/framework/Wsat/pages/config.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/framework/Wsat/pages/layout/TWsatLayout.php b/framework/Wsat/pages/layout/TWsatLayout.php new file mode 100644 index 00000000..30e52f44 --- /dev/null +++ b/framework/Wsat/pages/layout/TWsatLayout.php @@ -0,0 +1,32 @@ +validateSecurity(); + } + + private function validateSecurity() { + if ($this->Session["wsat_password"] !== $this->getService()->getPassword()) { + if (!$this->getPage() instanceof TWsatLogin) { + $url = $this->Service->constructUrl('TWsatLogin'); + $this->Response->redirect($url); + } + } + } + + public function logout() { + $this->Session["wsat_password"] = ""; + $url = $this->Service->constructUrl('TWsatLogin'); + $this->Response->redirect($url); + } + +} + +?> \ No newline at end of file diff --git a/framework/Wsat/pages/layout/TWsatLayout.tpl b/framework/Wsat/pages/layout/TWsatLayout.tpl new file mode 100644 index 00000000..47068a3f --- /dev/null +++ b/framework/Wsat/pages/layout/TWsatLayout.tpl @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + +
+
+
+
Code Generation
+
    +
  • +
  • +
+
+
+ +
+ +
+ +
+
+ + +
+ + \ No newline at end of file diff --git a/framework/Wsat/themes/.htaccess b/framework/Wsat/themes/.htaccess new file mode 100644 index 00000000..1caf5e97 --- /dev/null +++ b/framework/Wsat/themes/.htaccess @@ -0,0 +1 @@ +allow from all diff --git a/framework/Wsat/themes/PradoSoft/imgs/arrowdown.gif b/framework/Wsat/themes/PradoSoft/imgs/arrowdown.gif new file mode 100644 index 00000000..1b508cd6 Binary files /dev/null and b/framework/Wsat/themes/PradoSoft/imgs/arrowdown.gif differ diff --git a/framework/Wsat/themes/PradoSoft/imgs/mantisbg.jpg b/framework/Wsat/themes/PradoSoft/imgs/mantisbg.jpg new file mode 100644 index 00000000..ee06998d Binary files /dev/null and b/framework/Wsat/themes/PradoSoft/imgs/mantisbg.jpg differ diff --git a/framework/Wsat/themes/PradoSoft/imgs/pradologo.gif b/framework/Wsat/themes/PradoSoft/imgs/pradologo.gif new file mode 100644 index 00000000..3b073b80 Binary files /dev/null and b/framework/Wsat/themes/PradoSoft/imgs/pradologo.gif differ diff --git a/framework/Wsat/themes/PradoSoft/style.css b/framework/Wsat/themes/PradoSoft/style.css new file mode 100644 index 00000000..5424388b --- /dev/null +++ b/framework/Wsat/themes/PradoSoft/style.css @@ -0,0 +1,123 @@ +html, body{ + margin: 0px; + padding: 0px; + font-family: 'Lucida Grande', Verdana, Geneva, Lucida, Helvetica, Arial, sans-serif; + font-weight: normal; +} + +#header { + font-size:25px; + font-weight:bold; + color: #666; +} + +.logo{ + width: 204px; + height:100px; + background-image: url('imgs/pradologo.gif'); + background-repeat: no-repeat; + float: left; +} + +.mantisbg{ + width: 221px; + height: 100px; + background-image: url('imgs/mantisbg.jpg'); + background-repeat: no-repeat; + float: right; +} + +.mainmenu { + padding:10px; + padding-right:10px; + background:#EDEDED; + border-bottom: 1px solid #A6A6A6; + border-top: 1px solid #DCDCDC; + color:white; + text-align:right; + font-size: 10pt; +} + +.mainmenu a { + color:#737373; + text-decoration:none; +} + +.mainmenu a:hover { + color: #FF0000; +} + +#toc { + background-color: #F3F3F3; + width:220px; + padding:0px 10px 0px 10px; + float: left; +} + +#content { + padding: 1em 1em 1em 1em; + line-height: 135%; + float: left; +} + +.topic { + font-size: 9pt; + padding: 0px 0px 0px 0px; +} + +.topic div { + background-image: url('imgs/arrowdown.gif'); + background-repeat: no-repeat; + background-position: left center; + margin: 0px; + font-size: 8pt; + font-weight:bold; + color:#2A480A; + padding: 5px; + padding-left: 15px; + border-top: 1px solid #fff; + border-bottom: 1px solid #E2E2E2; +} + +.topic ul +{ + margin: 0px; + padding: 0px; +} + +.topic ul li +{ + list-style: none; + margin: 0px; + padding: 5px; + padding-left: 15px; + border-bottom: 1px dotted #D8D8D8; +} + +.topic a { + color:#4F811A; + font-size: 8pt; + text-decoration: none; +} + +.topic a:hover { + color:#2A480A; +} + +/* form styles */ +.form_row{ + margin: 10px; +} + +.in_text{ + width: 250px; +} + +#footer { + clear:both; + color: gray; + font-size:8pt; + text-align:center; + margin-top:25px; + padding:10px; +} \ No newline at end of file -- cgit v1.2.3