Browse Source

Shop product images reordering in control panel, migration, fixes

Vova Tkach 5 years ago
parent
commit
c8f236eb4d

File diff suppressed because it is too large
+ 3619 - 0
assets/cp.scripts.js


File diff suppressed because it is too large
+ 0 - 0
assets/cp.scripts.js.go


+ 1 - 1
consts/consts.go

@@ -5,7 +5,7 @@ import (
 )
 
 const AssetsPath = "assets"
-const AssetsVersion = "49"
+const AssetsVersion = "50"
 const DirIndexFile = "index.html"
 
 // Bootstrap resources

+ 1 - 1
engine/fetdata/shop.go

@@ -379,7 +379,7 @@ func (this *Shop) load() *Shop {
 			WHERE
 				shop_product_images.product_id IN (` + strings.Join(product_ids, ", ") + `)
 			ORDER BY
-				shop_product_images.filename ASC
+				shop_product_images.ord ASC
 			;`,
 		); err == nil {
 			defer rows.Close()

+ 1 - 1
engine/fetdata/shop_product.go

@@ -34,7 +34,7 @@ func (this *ShopProduct) load() *ShopProduct {
 		WHERE
 			shop_product_images.product_id = ?
 		ORDER BY
-			shop_product_images.filename ASC
+			shop_product_images.ord ASC
 		;`,
 		this.object.A_id,
 	); err == nil {

+ 5 - 2
modules/module_index_act_mysql_setup.go

@@ -241,8 +241,11 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 		// Table: shop_product_images
 		if _, err = tx.Exec(
 			`CREATE TABLE shop_product_images (
+				id int(11) NOT NULL AUTO_INCREMENT,
 				product_id int(11) NOT NULL,
-				filename varchar(255) NOT NULL
+				filename varchar(255) NOT NULL,
+				ord int(11) NOT NULL DEFAULT '0',
+				PRIMARY KEY (id)
 			) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
 		); err != nil {
 			tx.Rollback()
@@ -466,7 +469,7 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 			return
 		}
 		if _, err = tx.Exec(
-			`INSERT INTO settings (name, value) VALUES ('database_version', '000000010');`,
+			`INSERT INTO settings (name, value) VALUES ('database_version', '000000011');`,
 		); err != nil {
 			tx.Rollback()
 			wrap.MsgError(err.Error())

+ 7 - 3
modules/module_shop.go

@@ -220,18 +220,21 @@ func (this *Modules) shop_GetAllProductImages(wrap *wrapper.Wrapper, product_id
 	result := ``
 	rows, err := wrap.DB.Query(
 		`SELECT
+			id,
 			product_id,
 			filename
 		FROM
 			shop_product_images
 		WHERE
 			product_id = ?
+		ORDER BY
+			ord ASC
 		;`,
 		product_id,
 	)
 	if err == nil {
 		defer rows.Close()
-		values := make([]string, 2)
+		values := make([]string, 3)
 		scan := make([]interface{}, len(values))
 		for i := range values {
 			scan[i] = &values[i]
@@ -239,7 +242,7 @@ func (this *Modules) shop_GetAllProductImages(wrap *wrapper.Wrapper, product_id
 		for rows.Next() {
 			err = rows.Scan(scan...)
 			if err == nil {
-				result += `<div class="attached-img"><a href="/products/images/` + html.EscapeString(string(values[0])) + `/` + html.EscapeString(string(values[1])) + `" title="` + html.EscapeString(string(values[1])) + `" target="_blank"><img id="pimg_` + string(values[0]) + `_` + strings.Replace(string(values[1]), ".", "_", -1) + `" src="/products/images/` + string(values[0]) + `/thumb-0-` + string(values[1]) + `" onerror="WaitForFave(function(){fave.ShopProductsRetryImage(this, 'pimg_` + string(values[0]) + `_` + strings.Replace(string(values[1]), ".", "_", -1) + `');});" /></a><a class="remove" onclick="fave.ShopProductsDeleteImage(this, ` + html.EscapeString(string(values[0])) + `, '` + html.EscapeString(string(values[1])) + `');"><svg viewBox="1 1 11 14" width="10" height="12" class="sicon" version="1.1"><path fill-rule="evenodd" d="M11 2H9c0-.55-.45-1-1-1H5c-.55 0-1 .45-1 1H2c-.55 0-1 .45-1 1v1c0 .55.45 1 1 1v9c0 .55.45 1 1 1h7c.55 0 1-.45 1-1V5c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zm-1 12H3V5h1v8h1V5h1v8h1V5h1v8h1V5h1v9zm1-10H2V3h9v1z"></path></svg></a></div>`
+				result += `<div class="attached-img" data-id="` + html.EscapeString(string(values[0])) + `"><a href="/products/images/` + html.EscapeString(string(values[1])) + `/` + html.EscapeString(string(values[2])) + `" title="` + html.EscapeString(string(values[2])) + `" target="_blank"><img id="pimg_` + string(values[1]) + `_` + strings.Replace(string(values[2]), ".", "_", -1) + `" src="/products/images/` + string(values[1]) + `/thumb-0-` + string(values[2]) + `" onerror="WaitForFave(function(){fave.ShopProductsRetryImage(this, 'pimg_` + string(values[1]) + `_` + strings.Replace(string(values[2]), ".", "_", -1) + `');});" /></a><a class="remove" onclick="fave.ShopProductsDeleteImage(this, ` + html.EscapeString(string(values[1])) + `, '` + html.EscapeString(string(values[2])) + `');"><svg viewBox="1 1 11 14" width="10" height="12" class="sicon" version="1.1"><path fill-rule="evenodd" d="M11 2H9c0-.55-.45-1-1-1H5c-.55 0-1 .45-1 1H2c-.55 0-1 .45-1 1v1c0 .55.45 1 1 1v9c0 .55.45 1 1 1h7c.55 0 1-.45 1-1V5c.55 0 1-.45 1-1V3c0-.55-.45-1-1-1zm-1 12H3V5h1v8h1V5h1v8h1V5h1v8h1V5h1v9zm1-10H2V3h9v1z"></path></svg></a></div>`
 			}
 		}
 	}
@@ -1051,7 +1054,8 @@ func (this *Modules) RegisterModule_Shop() *Module {
 							`</div>` +
 							`</div>` +
 							`</div>` +
-							`</div>`
+							`</div>` +
+							`<script>WaitForFave(function(){Sortable.create(document.getElementById('list-images'),{animation:0,onEnd:function(evt){var orderData={};$('#list-images div.attached-img').each(function(i,v){orderData[$(v).data('id')]=i;});fave.ShopProductsImageReorder('shop-images-reorder',orderData);},});});</script>`
 					},
 				},
 				{

+ 3 - 1
modules/module_shop_act_upload_image.go

@@ -61,10 +61,12 @@ func (this *Modules) RegisterAction_ShopUploadImage() *Action {
 									if _, err := tx.Exec(
 										`INSERT INTO shop_product_images SET
 											product_id = ?,
-											filename = ?
+											filename = ?,
+											ord = ?
 										;`,
 										utils.StrToInt(pf_id),
 										target_file_name,
+										(utils.GetCurrentUnixTimestamp() + int64(i-1)),
 									); err != nil {
 										return err
 									}

+ 1 - 0
support/migrate/000000001.go

@@ -16,4 +16,5 @@ var Migrations = map[string]func(*sqlw.DB, string) error{
 	"000000008": Migrate_000000008,
 	"000000009": Migrate_000000009,
 	"000000010": Migrate_000000010,
+	"000000011": Migrate_000000011,
 }

+ 21 - 0
support/migrate/000000011.go

@@ -0,0 +1,21 @@
+package migrate
+
+import (
+	"golang-fave/engine/sqlw"
+)
+
+func Migrate_000000011(db *sqlw.DB, host string) error {
+	if _, err := db.Exec(`ALTER TABLE shop_product_images ADD id INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;`); err != nil {
+		return err
+	}
+
+	if _, err := db.Exec(`ALTER TABLE shop_product_images ADD COLUMN ord INT(11) NOT NULL DEFAULT 0 AFTER filename;`); err != nil {
+		return err
+	}
+
+	if _, err := db.Exec(`UPDATE shop_product_images SET ord = id;`); err != nil {
+		return err
+	}
+
+	return nil
+}

+ 4 - 1
support/schema.sql

@@ -79,8 +79,11 @@ CREATE TABLE shop_filters_values (
 	PRIMARY KEY (id)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 CREATE TABLE shop_product_images (
+	id int(11) NOT NULL AUTO_INCREMENT,
 	product_id int(11) NOT NULL,
-	filename varchar(255) NOT NULL
+	filename varchar(255) NOT NULL,
+	ord int(11) NOT NULL DEFAULT '0',
+	PRIMARY KEY (id)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 CREATE TABLE shop_products (
 	id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',

+ 2 - 0
xml.go

@@ -112,6 +112,8 @@ func xml_gen_offer_pictures(db *sqlw.DB, conf *config.Config, product_id int) st
 			shop_product_images
 		WHERE
 			shop_product_images.product_id = ?
+		ORDER BY
+			shop_product_images.ord ASC
 		;`,
 		product_id,
 	)

Some files were not shown because too many files changed in this diff