How to add delete button

Problem Add Delete button in AdminFile/update under New Attribute Create actionDeleteAttr Pass Behat tests How Add Delete button in /protected/adminFile/_form.php <tbody> <?php foreach($model->fileAttributes as $fa) { ?> <tr class="row-edit-<?= $fa->id ?>"> <td> <?= $fa->attribute->attribute_name ?> </td> <td> <?= $fa->value ?> </td> <td> <?= $fa->unit ? $fa->unit->name : '' ?> </td> <td><a role="button" class="btn btn-edit js-edit" data="<?= $fa->id ?>">Edit</a></td> <td><a role="button" class="btn js-delete" name="delete_attr" data="<?= $fa->id ?>">Delete</a></td> </tr> <?php } ?> </tbody> <script> $('.js-delete').click(function (e) { e.preventDefault(); id = $(this).attr('data'); console.log(id); row = $('.row-edit-' + id); console.log(row); if (id) { $.post('/adminFile/deleteAttr', { 'id': id }, function(result) { if (result) { // console.log(result); } }, 'json'); } window.location.reload(); }) </script> Create actionDeleteAttr in /controller/AdminFileController.php public function actionDeleteAttr() { if (!Yii::app()->request->isPostRequest) throw new CHttpException(404, "The requested page does not exist."); if (isset($_POST['id'])) { $attribute = FileAttributes::model()->findByPk($_POST['id']); if ($attribute) { $attribute->delete(); Yii::app()->end(); } } } Create admin-file.feature @admin-file @issue-457 Feature: An admin user can edit and delete attribute in admin file page As an admin user I can edit/delete attribute So that I can associate various attributes to files Background: Given Gigadb web site is loaded with production-like data @ok @issue-457 @javascript Scenario: Guest user cannot visit admin file update page Given I am not logged in to Gigadb web site When I go to "/adminFile/update/" Then I should see "Login" @ok @issue-457 @javascript Scenario: Sign in as admin and visit admin file update page and see New Attribute, Edit, Delete buttons Given I sign in as an admin When I am on "/adminFile/update/id/13973" Then I should see a button "New Attribute" And I should see a button input "Edit" And I should see a button input "Delete" @ok @issue-457 @javascript Scenario: Sign in as admin to delete attribute Given I sign in as an admin And I am on "/adminFile/update/id/13973" And I should see a button input "Delete" When I press "Delete" And I wait "3" seconds Then I should not see a button "Delete" Run behat test with Database set up 4.1 only accptance test #!/usr/bin/env bash set -e -u ./tests/acceptance #./tests/unit_functional #./tests/coverage 4.2 change tag to @wip ...

September 23, 2020 · 3 min · 508 words · Ken Cho

How to make go to page feature

Problem To add a go to page feature in navigating file table. Details refer to this issue View files from large db #437 How Create a Go to page button match the button style with the whole webpage create btn_click class for this onclick button create input box for number, and assign id=pageTarget <style> .btn_click { border: solid 1px #0eb23c; color: #0fad59; padding: 4px 6px 3px 6px; text-decoration: none; background-color: Transparent; outline:none; } input { width: 3%; } input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; } .text_box { color: #0fad59; background: #fff; border: solid 1px #0eb23c; outline:none; } </style> <button class="btn_click" onclick="goToPage()"><strong>Go to page</strong></button> <input type="number" id="pageTarget" class="text_box"> <a class="color-background"><strong> of <?= $files->getDataProvider()->getPagination()->getPageCount()?></strong></a> Create a goToPage() function in JavaScript document.getElementById('pageTarget').value gets the value of the input box <?php echo $model->identifier?> gets the paper ID number <?php echo $files->getDataProvider()->getPagination()->getPageCount()?> gets the max page count some requirements: disable input box arrows when userInput > max, return to max when userInput < min, return to min window.location.pathname will get current page url, will crash when go to page 2 and then press 1 so to create an array with default values: let targetUrlArray = ["", "dataset", "view", "id", pageID]; function goToPage() { var targetPageNumber = document.getElementById('pageTarget').value; var pageID = <?php echo $model->identifier?>; //To validate page number var userInput = parseInt(targetPageNumber); var max = <?php echo $files->getDataProvider()->getPagination()->getPageCount() ?>; //To output total pages // console.log(max); var min = 1; if (userInput >= min && userInput <= max) { console.log("Valid page number!"); }else if (userInput > max) { targetPageNumber = max; console.log("Error, return to " + max); } else if (userInput < min) { targetPageNumber = min; console.log("Error, return to " + min); } // var targetUrlArray = Array.apply(null, Array(5)).map(function(_,i) { return window.location.pathname.split("/")[i]});] // Create array with default values let targetUrlArray = ["", "dataset", "view", "id", pageID]; targetUrlArray.push('Files_page', targetPageNumber); window.location = window.location.origin + targetUrlArray.join("/"); // Uncomment will show the target url in console. // console.log(window.location.origin + targetUrlArray.join("/")) } Behat test PhantomJS has been discontinued, so it cannot simulate pressing action on Go to page button. In order to do so, behat.yml and docker-compose.yml need to be updated. ...

August 18, 2020 · 4 min · 842 words · Ken Cho

Learn, todo and done 22-26/6/20

Learn Docker TDD Codeception PHPUnit Yii2 Todo Done Issue #291 Review PR#452 Issue #423 Issue #425 Issue #440 Reference

June 22, 2020 · 1 min · 19 words · Ken Cho

Learn, todo and done 15-19/6/20

Learn Docker TDD PHP standard PHPUnit Codeception Yii1.1 and Yii2 Todo Issue #423 Issue #440 Issue #425 Problem Done Created PR for issue #291 PHPUnit doc, YouTube PHP Standards: PSR-1, PSR-2 and PSR-12 Reference

June 15, 2020 · 1 min · 34 words · Ken Cho

Learn, todo and done 8-12/6/20

Learn Docker PostgreSQL OOP progress Yii1.1 framework utterances Todo Problem For Issue #291, the codes in local develop branch is huge different from that in production server, a cascade of changes will be needed. Yii1.1 blog update Home page from /site/index to /site/post in /layouts/main.php Done Fixed issue #421 Fixed issue #441 Issue #291 Reference How to add Utterances in Hugo post utterances

June 8, 2020 · 1 min · 63 words · Ken Cho