Transfer from old admin to new

Verze:

14. 02. 2023

Zodpovědná osoba:

Dominik Šlechta

Process of changing the administration to a new version

    • Copy js files and scss files (create sass folder and add new sass files for admin from demo), change compilation in webpack.mix.js
    • Reinstall Bootstrap - make sure to also update the JS files in the resources folder! You can rename the old ones to something like _old (be careful with the FRONT! If needed, duplicate them instead).
    • Add variables
    • Bulk change of column classes - col-xs-12 to col-12 hidden to d-none, buttons etc. - see http://upgrade-bootstrap.bootply.com/ (all in složce fencee/app/presenters/Admin)
    • Layout modification according to demoweb
      • Logo modification
      • Edit navigace.latte
        replace: 'btn btn-default selected' : 'btn btn-default' =>  'selected' : ' '
        add to n:class: 'icon-name ico-before'
        remove <i> icons and col-12 from navigation
      • Edit right menu - see demo
    • Gradual overwriting of container classes, changing the structure of incorrectly nested row and col.
    • Edit app.js - see demoweb
    • Edit router + adding functions to presenters
      • $adminRoutes[] = new Route('/admin/menu/labeled[/<checkbox_id [0-9]+>]', 'Menu:labeled') + renderLabeled
    • Replace tables - here an example - see demo - via regexes see below, check if everything has really changed (it likes to throw stack overflow error), for example statelist
      <div class="custom-table">
                  <div class="table-head">
                      <div class="table-row">
      
                          <div class="table-caption">{_admin.table.name}</div>
                          <div class="table-caption">{_admin.table.note}</div>
                          <div class="table-caption"></div>
                      </div>
                  </div>
      
      
                  <div class="table-body">
                      <div class="table-row" n:foreach="$files as $file" >
                          <div class="table-cell ">
                              {$file->name|upper}
                          </div>
      
                          <div class="table-cell">
                              {$file->note}
                          </div>
      
      
                          <div class="table-cell buttons-on-end no-margins">
                              <a n:href="rescue! file_id => $file->id" class="btn btn-ghost ">{_admin.button.recovery}</a>
                          </div>
                      </div>
                  </div>
              </div>
    • Overwriting checkboxes and radio
      • search this $form["hidden"]->items,$form["menu_id"]->items, $form["vat"]->items and after checking, insert the following
        <label class="formLabel radio--fake" n:name="hidden:$key">
        	<input n:name="hidden:$key">
        	<div class="fake"></div>
        	<span>{_$label}</span>
        </label>
      • search this $form["supplementCheckbox"]->items, <label class="formLabel" n:name="virtual"> and after checking, insert the following + form
        <label class="formLabel check--fake" n:name="supplementCheckbox:$key">
        	<input n:name="supplementCheckbox:$key">
        	<span class="fake"></span>
        	<span>{$label}</span>
        </label>​
    • Copy the bottom bar to the necessary templates - search for this btn btn-success saveFormButton
    • Gradual change of the upper part - menu/item product/item atd.
    • Gradually overwrite tree.latte files
    • Refactor the dashboard (most parts can just be copied over, but it's better to double-check everything fits – app/components/Dashboard – includes dashboard.latte, PHP files, and the respective subfolders).
  • Adding new things (sliding bar, etc.)
  • fa fa-pencil-square-o, fa fa-pencil-square-o - selection of edit buttons - delete icon and change to btn btn-edit - see demo (or leave ajax)

  • fa fa-trash, fa fa-trash-o - selection of trash buttons - delete icon and change to btn btn-trash - see demo (or leave ajax)

  • btn-trash - remove text inside - mostly {_admin.button.to_bin}
  • class="ajax btn btn-success btn-sm" - where there is a hide or show function, put away the icon and change it class="ajax btn btn-isVisible"
    class="ajax btn btn-danger btn-sm" where there is a hide or show function, put away the icon and change it class="ajax btn btn-isVisible notVisible"
    class="ajax btn btn-default btn-sm disabled"
    where there is an up function, take away the icon and change it to class="ajax btn btn-up disabled"
    class="ajax btn btn-default btn-sm"
    where there is an up function, take away the icon and change it to class="ajax btn btn-up"
    class="ajax btn btn-default btn-sm disabled"
    where there is an down function, take away the icon and change it to class="ajax btn btn-down disabled"
    class="ajax btn btn-default btn-sm" where there is an down function, take away the icon and change it to class="ajax btn btn-down "
    - then delete it wherever this is:
    <i class="fa fa-eye"></i>,

    <i class="fa fa-eye-slash"></i>,
    <i class="fa fa-arrow-circle-up"></i>,
    <i class="fa fa-arrow-circle-down"></i>,
    <i class="fa fa-file-image-o"></i>
    <i class="fa fa-envelope-o"></i>

    <i class="fa fa-level-up"></i>
    <i class="fa fa-user"></i> (watchout for jstree)
  • refactor clacs controlTd class to left-part, add class left-part where are buttons like btn-up, btn-isVisible etc.
  • sortableTable - replace fordata-table-sortable, delete class="sortable" data-sort="string" and <i class="fa fa-sort"></i>
  • Refactor assets/admin - Primarily libs a jstree
  • Refactor {first} to {if $iterator->isFirst()} and {/first} to {/if}  gradually - search in project
  • Refactor {last} to {if $iterator->isLast()} and {/last} to {/if}  gradually - search in project
  • Search form-group and where there's a column below it, add to it first <div class="row"> and close before the end

Menu items and product

First we edit BasePresenter.php according to the demo

Menufactory - copy from this line $form->addCheckbox('c_addToGallery', 'Přidat obrázky do galerie') - approx. line 239 from the demo up to $addToFiles->addUpload('file_input', 'Soubor:')
->addConditionOn($form['c_addToFiles'], $form::EQUAL, true) - approx. 326
->setRequired('Přidejte soubor, který chcete nahrát.');
and add to project

Insights for optimization

Regexes

col-(xs|sm|md|lg)-offset-(\d+) - all column offsets (the replacement is then as follows offset-$1-$2)

col-xs-(\d+) - all xs columns (the replacement is then as follows col-$1) in $1 is then whole match

( *?<section class=".*?center-panel.*?".*?>) - selects centerPanel the beginning of the section, the end of the rightPanel section unfortunately we have to select manually and insert there the end of the two divs (you need to check also the pages where there is only centerPanel, it worked well for me to search </section> in the administration) </div></div> in $1 is then the whole match, then you need to nest {form neco} up to the column

- replace <div class="col-12 col-md-12 col-lg-10 right-part-wrapper">
<div class="row">\n $1

^(<div class="row">(?:(\n|\r|\s)*)?<section class="(?:.*)?center-panel(?:.*)?"(?:.*)?>)$ - select centerpanel and row before

col-(?!(?:12))(\d+) col - selection of classes where there is no responsiveness - col-1-11, we can replace just like in the demo, replace "col-12 col"

"col-(?!(?:12))(\d+)" - selection of classes where there is no responsiveness and no other class - col-1-11, we can replace like in the demo - arrow replacement "col-12 col-md-$1"

col-12 col-md-2 col-lg-(\d+) right-panel rewrite to col-12 col-md-3 right-panel

( *?<section class=".*?right-panel.*?".*?>) - select rightPanel the beginning of the section and insert <div class="right-panel-content">, unfortunately we have to select the end of the rightPanel section manually and insert the end of the div

Table regexes

<table([^>]*?)class="table table-striped((?:.|\s)*?)">((?:.|\s)*?)<\/table> - select all tables - replace for <div$1class="custom-table $2">$3</div>

(<div(?:[^>]*?)class="custom-table(?:.|\s)*?">(?:.|\s)*?)<thead>((?:.|\s)*?)<\/thead>((?:.|\s)*?<\/div>) - thead change $1<div class="table-head">$2</div>$3

(<div(?:[^>]*?)class="custom-table(?:.|\s)*?">(?:.|\s)*?)<tbody>((?:.|\s)*?)<\/tbody>((?:.|\s)*?<\/div>) - tbody change $1<div class="table-body">$2</div>$3

(<div class="table-body(?:.|\s)*?">(?:.|\s)*?)<tr((?:.|\s)*?)>((?:.|\s)*?)<\/tr> - table-row change $1<div class="table-row" $2>$3</div> - try multiple times

(<div class="table-head(?:.|\s)*?">(?:.|\s)*?)<tr((?:.|\s)*?)>((?:.|\s)*?)<\/tr> - table-row change $1<div class="table-row" $2>$3</div> - try multiple times

(<div class="table-body(?:.|\s)*?">(?:.|\s)*?)<td((?:.|\s)*?)>((?:.|\s)*?)<\/td> - table-cell změna $1<div class="table-cell" $2>$3</div> - try multiple times

(<div class="table-head(?:.|\s)*?">(?:.|\s)*?)<th((?:.|\s)*?)>((?:.|\s)*?)<\/th> - table-caption change $1<div class="table-caption" $2>$3</div> - try multiple times

class="table-cell" class="lastTd" - change to class="table-cell lastTd"

class="table-cell" class="controlTd" + search for controlTd - change to class="table-cell left-part"

Searching

<(?:[^>]*?)class="(?:[^>]*?)"(?:[^>]*?)n:class="(?:[^>]*?)"(?:[^>]*?)> - class and n:class - duplicated

Errors

class="partialForm" {if $galleries || $files}style='display:block;'{/if}" - here is probably an extra quote, it breaks the formatting and layout

Replace bootstrap classes (outside of regex - only latte so far!)

.hidden .d-none (only latte! and one by one! - we only want classes, I haven't found any other classes)
.hidden-xs .d-none
.hidden-sm .d-sm-none
.hidden-md .d-md-none
.hidden-lg .d-lg-none
.visible-xs .d-block.d-sm-none
.visible-sm .d-none.d-sm-block.d-md-none
.visible-md .d-none.d-md-block.d-lg-none
.visible-lg .d-none.d-lg-block.d-xl-none

 

Completing the translation - according to the demo

Review and check if any translation in git has been deleted, better to do it one by one and then catch up if it has been deleted by mistake

SQL

New configs

INSERT INTO settings_config (id, name, value, hidden, type, note, visible)
VALUES ('ADMIN_ACTIONS_PER_PAGE', 'Počet akcí na stránku', '20', 0, 'input', '', 0),
('ENABLE_MENU_STRUCTURE_DUPLICATION',	'Zapnout možnost duplikace struktury ',	'0',	0,	'input',	'',	0),
('ADMIN_INSTAGRAM', 'Přidat tlačítko instagramu do adminu pro přihlášení', '0', 0, 'input',
'Přidá tlačítko přihlásit se přes instagram do nastavení webu, po přihlášení se zobrazí instagram příspěvky na webu.', 0),
('ADMIN_LOGO_SRC', 'Admin - cesta k logu', '/assets/logo.png', 0, 'input', '', 0),
('ADMIN_MODULE_ORDER_DISTRIBUTOR', 'ADMIN_MODULE_ORDER_DISTRIBUTOR', 'ADMIN_MODULE_ORDER_DISTRIBUTOR ', 0, 'input', '', 0),
('ADMIN_SUPPLIERS', 'Aktivovat funkcionalitu dodavatelů', '1', 0, 'input',
'Zobrazí v treemenu moznosti s dodavatelem (vytvorení, editace, seznam) a přidá položku do tvorby a úpravy produktu.', 0),
('ADMIN_TAB_ACTIONS', 'ADMIN_TAB_ACTIONS', 'ADMIN_TAB_ACTIONS ', 0, 'input', '', 0),
('ADMIN_TAB_CRM', 'ADMIN_TAB_CRM', 'ADMIN_TAB_CRM ', 1, 'input', '', 0),
('ADMIN_TAB_DEALER', 'ADMIN_TAB_DEALER', 'ADMIN_TAB_DEALER ', 0, 'input', '', 0),
('ADMIN_TAB_ESHOP', 'ADMIN_TAB_ESHOP', 'ADMIN_TAB_ESHOP ', 0, 'input', '', 0),
('ADMIN_TAB_FILES', 'ADMIN_TAB_FILES', 'ADMIN_TAB_FILES ', 0, 'input', '', 0),
('ADMIN_TAB_GALLERY', 'ADMIN_TAB_GALLERY', 'ADMIN_TAB_GALLERY ', 0, 'input', '', 0),
('ADMIN_TAB_NEWSLETTER', 'ADMIN_TAB_NEWSLETTER', 'ADMIN_TAB_NEWSLETTER ', 0, 'input', '', 0),
('ADMIN_TAB_SETTINGS', 'ADMIN_TAB_SETTINGS', 'ADMIN_TAB_SETTINGS ', 0, 'input', '', 0),
('ADMIN_TAB_STATISTIC', 'Statistiky', '1', 0, 'input', '', 0),
('ADMIN_TAB_USERS', 'ADMIN_TAB_USERS', 'ADMIN_TAB_USERS ', 0, 'input', '', 0),
('BANNED_DOMAINS', 'Vyřazené e-mailové domény', 'verizon.net\nssemarketing.net\ncomcast.net\npobox.com\ncharter.net\nfrontier.com\ncox.net', 0,
'textarea', '', 0),
('BANNED_PHONES', 'Zakázané telefony', '+1 213 425 1453\n12134251453', 0, 'textarea', '', 0),
('CURRENCY_SYMBOLS', 'Symboly měn', 'CZK::Kč\nEUR::€', 0, 'textarea', 'CURRENCY::SYMBOL\nCURRENCY::SYMBOL\nCURRENCY::SYMBOL', 0),
('IS_ESHOP', 'IS_ESHOP', 'IS_ESHOP', 0, 'input', '', 0),
('SUPPLIER_MENU_ID', 'ID menu dodavatelů', '4', 0, 'input', '', 0);

New tables

CREATE TABLE admin_overwatch
(
	id          INT(11)                            NOT NULL AUTO_INCREMENT,
	lang        INT(2)                             NOT NULL,
	work_id     VARCHAR(255) COLLATE utf8_czech_ci NOT NULL,
	`desc`      VARCHAR(255) COLLATE utf8_czech_ci NOT NULL,
	date        DATETIME                           NOT NULL,
	user        INT(11)                            DEFAULT NULL,
	target_item VARCHAR(255) COLLATE utf8_czech_ci DEFAULT NULL,
	PRIMARY KEY (id)
) ENGINE = InnoDB
	DEFAULT CHARSET = utf8
	COLLATE = utf8_czech_ci;


CREATE TABLE `settings_video` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `module_id` int(10) unsigned NOT NULL,
  `menus` varchar(100) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `folder` varchar(255) NOT NULL,
  `mask` varchar(255) NOT NULL,
  `format` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_czech_ci;

CREATE TABLE `video_detail` (
  `id` varchar(20) NOT NULL,
  `lang` tinyint(4) unsigned NOT NULL,
  `name` varchar(255) NOT NULL,
  `alt` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_czech_ci;

CREATE TABLE `image_detail` (
  `id` varchar(20) NOT NULL,
  `lang` tinyint(4) unsigned NOT NULL,
  `name` varchar(255) NOT NULL,
  `alt` varchar(255) NOT NULL,
  PRIMARY KEY (`id`,`lang`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;



CREATE TABLE `comment` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `lang` int(10) unsigned NOT NULL,
  `module_id` int(10) unsigned NOT NULL,
  `item_id` int(10) unsigned NOT NULL,
  `user_id` int(10) unsigned DEFAULT NULL,
  `name` varchar(100) DEFAULT NULL,
  `email` varchar(100) NOT NULL,
  `text` text NOT NULL,
  `date_inserted` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `hidden` tinyint(2) NOT NULL,
  `parent_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `module_id` (`module_id`),
  KEY `user_id` (`user_id`),
  CONSTRAINT `comment_ibfk_1` FOREIGN KEY (`module_id`) REFERENCES `module` (`id`) ON DELETE NO ACTION,
  CONSTRAINT `comment_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;


CREATE TABLE `help` (
  `id` varchar(30) NOT NULL,
  `modul` varchar(100) NOT NULL,
  `value` varchar(100) DEFAULT NULL,
  `lang` int(10) NOT NULL,
  KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;

CREATE TABLE `menu_item_x_user` (
  `menu_item_id` int(10) unsigned NOT NULL,
  `user_id` int(10) unsigned NOT NULL,
  `lang` tinyint(2) NOT NULL,
  PRIMARY KEY (`menu_item_id`,`user_id`,`lang`),
  KEY `user_id` (`user_id`),
  CONSTRAINT `menu_item_x_user_ibfk_1` FOREIGN KEY (`menu_item_id`) REFERENCES `menu_item` (`id`),
  CONSTRAINT `menu_item_x_user_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `user_x_supplement` (
  `user_id` int(10) unsigned NOT NULL,
  `supplement_id` int(10) unsigned NOT NULL,
  `lang` tinyint(4) unsigned NOT NULL,
  `value` text NOT NULL,
  `date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`user_id`,`supplement_id`,`lang`),
  KEY `supplement_id` (`supplement_id`),
  CONSTRAINT `user_x_supplement_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`),
  CONSTRAINT `user_x_supplement_ibfk_2` FOREIGN KEY (`supplement_id`) REFERENCES `supplement` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE `orders` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `lang` tinyint(2) NOT NULL,
  `lang_second` tinyint(4) DEFAULT NULL,
  `user_id` int(10) unsigned DEFAULT NULL,
  `second_address_id` int(10) unsigned DEFAULT NULL,
  `transport_id` int(10) unsigned NOT NULL,
  `payment_id` int(10) unsigned NOT NULL,
  `state_id` int(10) unsigned NOT NULL,
  `vo` tinyint(2) NOT NULL,
  `discount` int(11) NOT NULL,
  `user_name` varchar(255) NOT NULL,
  `user_address` varchar(255) NOT NULL,
  `user_city` varchar(255) NOT NULL,
  `user_zip` varchar(255) NOT NULL,
  `user_country` tinyint(2) NOT NULL DEFAULT 1,
  `user_email` varchar(255) NOT NULL,
  `user_phone` varchar(255) NOT NULL,
  `firm_name` varchar(255) DEFAULT NULL,
  `firm_id_number` varchar(255) DEFAULT NULL,
  `firm_vat_number` varchar(255) DEFAULT NULL,
  `newsletter` tinyint(4) DEFAULT NULL,
  `gateway_id` float DEFAULT NULL,
  `gateway_status` varchar(20) DEFAULT NULL,
  `note` text DEFAULT NULL,
  `time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `pohoda_exported` tinyint(2) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `prefix_order_user_id_foreign` (`user_id`),
  KEY `prefix_order_second_address_id_foreign` (`second_address_id`),
  KEY `prefix_order_transport_id_foreign` (`transport_id`),
  KEY `prefix_order_payment_id_foreign` (`payment_id`),
  KEY `prefix_order_state_id_foreign` (`state_id`),
  KEY `prefix_order_user_name_index` (`user_name`),
  KEY `prefix_order_user_city_index` (`user_city`),
  KEY `prefix_order_user_zip_index` (`user_zip`),
  KEY `prefix_order_user_email_index` (`user_email`),
  CONSTRAINT `prefix_order_payment_id_foreign` FOREIGN KEY (`payment_id`) REFERENCES `settings_payment` (`id`),
  CONSTRAINT `prefix_order_second_address_id_foreign` FOREIGN KEY (`second_address_id`) REFERENCES `order_second_address` (`id`),
  CONSTRAINT `prefix_order_state_id_foreign` FOREIGN KEY (`state_id`) REFERENCES `order_state` (`id`),
  CONSTRAINT `prefix_order_transport_id_foreign` FOREIGN KEY (`transport_id`) REFERENCES `settings_transport` (`id`),
  CONSTRAINT `prefix_order_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;


CREATE TABLE product_supplier(
	id           INT(10) UNSIGNED                   NOT NULL,
	lang         TINYINT(2)                         NOT NULL,
	hidden       TINYINT(2)                         NOT NULL,
	name         VARCHAR(255) COLLATE utf8_czech_ci NOT NULL,
	position     INT(11)                            NOT NULL,
	note         TEXT COLLATE utf8_czech_ci         NOT NULL,
	menu_item_id INT(11) DEFAULT NULL,
	PRIMARY KEY (id, lang),
	KEY prefix_product_supplier_name_index (name)
) ENGINE = InnoDB
	DEFAULT CHARSET = utf8
	COLLATE = utf8_czech_ci;

CREATE TABLE product_supplier_x_supplement(
	supplier_id   INT(10) UNSIGNED                               NOT NULL,
	supplement_id INT(10) UNSIGNED                               NOT NULL,
	lang          TINYINT(2)                                     NOT NULL,
	value         TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
	date          TIMESTAMP                                      NOT NULL DEFAULT '0000-00-00 00:00:00',
	PRIMARY KEY (supplier_id, supplement_id, lang),
	KEY prefix_supplier_x_supply_supply_id_foreign (supplement_id),
	CONSTRAINT prefix_supplier_x_supply_supplier_id_foreign FOREIGN KEY (supplier_id) REFERENCES product_supplier (id),
	CONSTRAINT prefix_supplier_x_supply_supply_id_foreign FOREIGN KEY (supplement_id) REFERENCES supplement (id)
) ENGINE = InnoDB
	DEFAULT CHARSET = utf8
	COLLATE = utf8_czech_ci;

Cleaning

DELETE FROM menu_item_x_supplement WHERE value = '';