[add] (view) add ImageDataList
This commit is contained in:
@@ -89,17 +89,10 @@ import ru.m.puzzlez.view.popup.PreviewPopup;
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function back():Void {
|
private function back():Void {
|
||||||
(if (game != null && game.state.status == COMPLETE) {
|
(game.state.status == COMPLETE ? Promise.promise(true) : ConfirmView.confirm("Exit?"))
|
||||||
Promise.promise(true);
|
.then(result -> {
|
||||||
} else {
|
|
||||||
ConfirmView.confirm("Exit?");
|
|
||||||
}).then(result -> {
|
|
||||||
if (result) {
|
if (result) {
|
||||||
if (game.state.status == COMPLETE) {
|
switcher.change(GameListFrame.ID, game.state.status);
|
||||||
switcher.change(GameListFrame.ID, COMPLETE);
|
|
||||||
} else {
|
|
||||||
switcher.back();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,83 +1,29 @@
|
|||||||
package ru.m.puzzlez.view;
|
package ru.m.puzzlez.view;
|
||||||
|
|
||||||
import haxework.view.data.DataView;
|
|
||||||
import haxework.view.form.ToggleButtonView;
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.frame.FrameView;
|
import haxework.view.frame.FrameView;
|
||||||
import haxework.view.popup.ConfirmView;
|
|
||||||
import ru.m.data.IDataSource;
|
|
||||||
import ru.m.puzzlez.core.GameState;
|
import ru.m.puzzlez.core.GameState;
|
||||||
import ru.m.puzzlez.core.Id.ImageId;
|
|
||||||
import ru.m.puzzlez.storage.GameStorage;
|
import ru.m.puzzlez.storage.GameStorage;
|
||||||
import ru.m.puzzlez.view.common.PaginatorView;
|
import ru.m.puzzlez.view.common.ImageDataList;
|
||||||
import ru.m.puzzlez.view.PuzzleImageView;
|
|
||||||
|
|
||||||
@:template class GameListFrame extends FrameView<GameStatus> {
|
@:template class GameListFrame extends FrameView<GameStatus> {
|
||||||
|
|
||||||
public static var ID(default, never) = "game_list";
|
public static var ID(default, never) = "game_list";
|
||||||
|
|
||||||
@:view("images") var imagesView:ActionDataView<ImageId, PuzzleImageView, Action>;
|
@:view("images") var imagesView:ImageDataList;
|
||||||
@:view("pages") var pagesView:PaginatorView;
|
|
||||||
private var loading:LoadingWrapper;
|
|
||||||
|
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
@:provide var storage:GameStorage;
|
@:provide var storage:GameStorage;
|
||||||
|
|
||||||
private var status:GameStatus;
|
|
||||||
private var page:Page;
|
|
||||||
|
|
||||||
private var data(default, set):DataPage<ImageId>;
|
|
||||||
|
|
||||||
private function set_data(value:DataPage<ImageId>):DataPage<ImageId> {
|
|
||||||
data = value;
|
|
||||||
imagesView.data = data.data;
|
|
||||||
pagesView.page = value;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super(ID);
|
super(ID);
|
||||||
loading = new LoadingWrapper(imagesView);
|
imagesView.source = storage;
|
||||||
page = {index: 0, count: 6, order: [{key: "date", reverse: true}]};
|
|
||||||
}
|
|
||||||
|
|
||||||
private function pageFactory(index:Int, value:Int):ToggleButtonView {
|
|
||||||
var result = new ToggleButtonView();
|
|
||||||
result.text = '${value}';
|
|
||||||
result.on = data.page.index == value;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function onShow(data:GameStatus):Void {
|
override public function onShow(data:GameStatus):Void {
|
||||||
page.index = 0;
|
imagesView.reset();
|
||||||
this.data = {
|
imagesView.page.filter = ["status" => data];
|
||||||
page: page,
|
imagesView.refresh();
|
||||||
total: 0,
|
|
||||||
data: [],
|
|
||||||
};
|
|
||||||
status = data;
|
|
||||||
page.filter = ["status" => status];
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function start(id:ImageId):Void {
|
|
||||||
storage.get(id).then(state -> switcher.change(GameFrame.ID, state));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function refresh():Void {
|
|
||||||
loading.promise = storage.getIndexPage(page).then(data -> this.data = data);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onAction(imageId:ImageId, action:Action):Void {
|
|
||||||
switch action {
|
|
||||||
case CLEAN:
|
|
||||||
ConfirmView.confirm("Delete state?").then(result -> {
|
|
||||||
if (result) {
|
|
||||||
storage.delete(imageId).then(_ -> refresh());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function back():Void {
|
private function back():Void {
|
||||||
|
|||||||
@@ -2,26 +2,8 @@
|
|||||||
style: frame
|
style: frame
|
||||||
views:
|
views:
|
||||||
- id: images
|
- id: images
|
||||||
$type: haxework.view.data.ActionDataView
|
$type: ru.m.puzzlez.view.common.ImageDataList
|
||||||
layout:
|
|
||||||
$type: haxework.view.layout.TailLayout
|
|
||||||
rowSize: 3
|
|
||||||
margin: 5
|
|
||||||
vAlign: middle
|
|
||||||
geometry.stretch: true
|
geometry.stretch: true
|
||||||
factory: ~ru.m.puzzlez.view.PuzzleImageView.factory
|
|
||||||
+onDataSelect: ~start
|
|
||||||
+onDataAction: ~onAction
|
|
||||||
geometry.margin: 5
|
|
||||||
overflow.y: scroll
|
|
||||||
- id: pages
|
|
||||||
$type: ru.m.puzzlez.view.common.PaginatorView
|
|
||||||
geometry.width: 100%
|
|
||||||
+onPageSelect: |
|
|
||||||
~(index) -> {
|
|
||||||
page.index = index;
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
- $type: haxework.view.form.ButtonView
|
- $type: haxework.view.form.ButtonView
|
||||||
text: Back
|
text: Back
|
||||||
geometry.position: absolute
|
geometry.position: absolute
|
||||||
|
|||||||
@@ -1,110 +1,40 @@
|
|||||||
package ru.m.puzzlez.view;
|
package ru.m.puzzlez.view;
|
||||||
|
|
||||||
import haxework.view.data.DataView;
|
|
||||||
import haxework.view.form.ButtonView;
|
import haxework.view.form.ButtonView;
|
||||||
import haxework.view.form.ToggleButtonView;
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.frame.FrameView;
|
import haxework.view.frame.FrameView;
|
||||||
import haxework.view.popup.ConfirmView;
|
|
||||||
import ru.m.data.IDataSource;
|
|
||||||
import ru.m.puzzlez.core.Id;
|
|
||||||
import ru.m.puzzlez.FileUtil;
|
import ru.m.puzzlez.FileUtil;
|
||||||
import ru.m.puzzlez.source.FileSource;
|
import ru.m.puzzlez.source.FileSource;
|
||||||
import ru.m.puzzlez.storage.GameStorage;
|
|
||||||
import ru.m.puzzlez.storage.ImageStorage;
|
import ru.m.puzzlez.storage.ImageStorage;
|
||||||
import ru.m.puzzlez.view.common.PaginatorView;
|
import ru.m.puzzlez.view.common.ImageDataList;
|
||||||
import ru.m.puzzlez.view.PuzzleImageView;
|
|
||||||
|
|
||||||
@:template class ImageListFrame extends FrameView<ImageListSource> {
|
@:template class ImageListFrame extends FrameView<ImageListSource> {
|
||||||
public static var ID = "image_list";
|
public static var ID = "image_list";
|
||||||
|
|
||||||
@:view("images") var imagesView:ActionDataView<ImageId, PuzzleImageView, Action>;
|
@:view("images") var imagesView:ImageDataList;
|
||||||
@:view("pages") var pagesView:PaginatorView;
|
|
||||||
@:view var select:ButtonView;
|
@:view var select:ButtonView;
|
||||||
|
|
||||||
@:provide var imageStorage:ImageStorage;
|
@:provide var imageStorage:ImageStorage;
|
||||||
@:provide var gameStorage:GameStorage;
|
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
|
||||||
private var source:ImageListSource;
|
|
||||||
private var loading:LoadingWrapper;
|
|
||||||
|
|
||||||
private var page:Page;
|
|
||||||
private var data(default, set):DataPage<ImageId>;
|
|
||||||
|
|
||||||
private function set_data(value:DataPage<ImageId>):DataPage<ImageId> {
|
|
||||||
data = value;
|
|
||||||
imagesView.data = data.data;
|
|
||||||
pagesView.page = data;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super(ID);
|
super(ID);
|
||||||
page = {index: 0, count: 6, order: [{key: "date", reverse: true}]};
|
|
||||||
loading = new LoadingWrapper(imagesView);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function pageFactory(index:Int, value:Int):ToggleButtonView {
|
|
||||||
var result = new ToggleButtonView();
|
|
||||||
result.text = '${value}';
|
|
||||||
result.on = data.page.index == value;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function onShow(data:ImageListSource):Void {
|
override public function onShow(data:ImageListSource):Void {
|
||||||
page.index = 0;
|
imagesView.reset();
|
||||||
this.data = {
|
|
||||||
page: page,
|
|
||||||
total: 0,
|
|
||||||
data: [],
|
|
||||||
};
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
source = data;
|
select.visible = data.source.id == FileSource.ID;
|
||||||
select.visible = source.source.id == FileSource.ID;
|
imagesView.page.filter = ["type" => data.type];
|
||||||
page.filter = ["type" => data.type];
|
imagesView.source = data.source;
|
||||||
refresh();
|
imagesView.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function selectFile():Void {
|
private function selectFile():Void {
|
||||||
FileUtil.browse().then((data:FileContent) -> {
|
FileUtil.browse().then((data:FileContent) -> {
|
||||||
var fileSource:FileSource = cast source.source;
|
var fileSource:FileSource = cast imageStorage.sources.get(FileSource.ID);
|
||||||
fileSource.append(data.content).then(_ -> refresh());
|
fileSource.append(data.content).then(_ -> imagesView.refresh());
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onAction(imageId:ImageId, action:Action):Void {
|
|
||||||
switch action {
|
|
||||||
case REMOVE:
|
|
||||||
var fileSource:FileSource = Std.instance(source.source, FileSource);
|
|
||||||
if (fileSource != null) {
|
|
||||||
ConfirmView.confirm("Delete image?").then(result -> {
|
|
||||||
if (result) {
|
|
||||||
fileSource.remove(imageId).then(_ -> refresh());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
case CLEAN:
|
|
||||||
ConfirmView.confirm("Delete state?").then(result -> {
|
|
||||||
if (result) {
|
|
||||||
gameStorage.delete(imageId).then(_ -> refresh());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function refresh():Void {
|
|
||||||
loading.promise = source.source.getIndexPage(page).then(data -> this.data = data);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function start(imageId:ImageId):Void {
|
|
||||||
gameStorage.get(imageId).then(state -> {
|
|
||||||
if (state != null) {
|
|
||||||
switcher.change(GameFrame.ID, state);
|
|
||||||
} else {
|
|
||||||
switcher.change(PresetFrame.ID, imageId);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,26 +2,8 @@
|
|||||||
style: frame
|
style: frame
|
||||||
views:
|
views:
|
||||||
- id: images
|
- id: images
|
||||||
$type: haxework.view.data.ActionDataView
|
$type: ru.m.puzzlez.view.common.ImageDataList
|
||||||
layout:
|
|
||||||
$type: haxework.view.layout.TailLayout
|
|
||||||
rowSize: 3
|
|
||||||
margin: 5
|
|
||||||
vAlign: middle
|
|
||||||
geometry.stretch: true
|
geometry.stretch: true
|
||||||
factory: ~ru.m.puzzlez.view.PuzzleImageView.factory
|
|
||||||
+onDataSelect: ~start
|
|
||||||
+onDataAction: ~onAction
|
|
||||||
geometry.margin: 5
|
|
||||||
overflow.y: scroll
|
|
||||||
- id: pages
|
|
||||||
$type: ru.m.puzzlez.view.common.PaginatorView
|
|
||||||
geometry.width: 100%
|
|
||||||
+onPageSelect: |
|
|
||||||
~(index) -> {
|
|
||||||
page.index = index;
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
- id: select
|
- id: select
|
||||||
$type: haxework.view.form.ButtonView
|
$type: haxework.view.form.ButtonView
|
||||||
text: Select...
|
text: Select...
|
||||||
|
|||||||
92
src/haxe/ru/m/puzzlez/view/common/ImageDataList.hx
Normal file
92
src/haxe/ru/m/puzzlez/view/common/ImageDataList.hx
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
package ru.m.puzzlez.view.common;
|
||||||
|
|
||||||
|
import haxework.view.data.DataView;
|
||||||
|
import haxework.view.form.ToggleButtonView;
|
||||||
|
import haxework.view.frame.FrameSwitcher;
|
||||||
|
import haxework.view.group.VGroupView;
|
||||||
|
import haxework.view.popup.ConfirmView;
|
||||||
|
import ru.m.data.IDataSource;
|
||||||
|
import ru.m.puzzlez.core.Id;
|
||||||
|
import ru.m.puzzlez.source.FileSource;
|
||||||
|
import ru.m.puzzlez.storage.GameStorage;
|
||||||
|
import ru.m.puzzlez.storage.ImageStorage;
|
||||||
|
import ru.m.puzzlez.view.common.PuzzleImageView;
|
||||||
|
|
||||||
|
@:template class ImageDataList extends VGroupView {
|
||||||
|
|
||||||
|
public var source:IDataIndex<ImageId>;
|
||||||
|
public var page:Page;
|
||||||
|
|
||||||
|
@:view("images") var imagesView:ActionDataView<ImageId, PuzzleImageView, Action>;
|
||||||
|
@:view("paginator") var paginatorView:PaginatorView;
|
||||||
|
private var loading:LoadingWrapper;
|
||||||
|
|
||||||
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
@:provide var gameStorage:GameStorage;
|
||||||
|
@:provide var imageStorage:ImageStorage;
|
||||||
|
|
||||||
|
public var data(default, set):DataPage<ImageId>;
|
||||||
|
|
||||||
|
private function set_data(value:DataPage<ImageId>):DataPage<ImageId> {
|
||||||
|
data = value;
|
||||||
|
imagesView.data = data.data;
|
||||||
|
paginatorView.page = data;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
loading = new LoadingWrapper(imagesView);
|
||||||
|
page = {index: 0, count: 6, order: [{key: "date", reverse: true}]};
|
||||||
|
}
|
||||||
|
|
||||||
|
private function pageFactory(index:Int, value:Int):ToggleButtonView {
|
||||||
|
var result = new ToggleButtonView();
|
||||||
|
result.text = '${value}';
|
||||||
|
result.on = data.page.index == value;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function start(imageId:ImageId):Void {
|
||||||
|
gameStorage.get(imageId).then(state -> {
|
||||||
|
if (state != null) {
|
||||||
|
switcher.change(GameFrame.ID, state);
|
||||||
|
} else {
|
||||||
|
switcher.change(PresetFrame.ID, imageId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onAction(imageId:ImageId, action:Action):Void {
|
||||||
|
switch action {
|
||||||
|
case REMOVE:
|
||||||
|
var fileSource:FileSource = cast imageStorage.sources.get(FileSource.ID);
|
||||||
|
if (fileSource != null) {
|
||||||
|
ConfirmView.confirm("Delete image?").then(result -> {
|
||||||
|
if (result) {
|
||||||
|
fileSource.remove(imageId).then(_ -> refresh());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
case CLEAN:
|
||||||
|
ConfirmView.confirm("Delete state?").then(result -> {
|
||||||
|
if (result) {
|
||||||
|
gameStorage.delete(imageId).then(_ -> refresh());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function refresh():Void {
|
||||||
|
loading.promise = source.getIndexPage(page).then(data -> this.data = data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reset():Void {
|
||||||
|
page.index = 0;
|
||||||
|
data = {
|
||||||
|
page: page,
|
||||||
|
total: 0,
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/haxe/ru/m/puzzlez/view/common/ImageDataList.yaml
Normal file
23
src/haxe/ru/m/puzzlez/view/common/ImageDataList.yaml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
views:
|
||||||
|
- id: images
|
||||||
|
$type: haxework.view.data.ActionDataView
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.TailLayout
|
||||||
|
rowSize: 3
|
||||||
|
margin: 5
|
||||||
|
vAlign: middle
|
||||||
|
geometry.stretch: true
|
||||||
|
factory: ~ru.m.puzzlez.view.common.PuzzleImageView.factory
|
||||||
|
+onDataSelect: ~start
|
||||||
|
+onDataAction: ~onAction
|
||||||
|
geometry.margin: 5
|
||||||
|
overflow.y: scroll
|
||||||
|
- id: paginator
|
||||||
|
$type: ru.m.puzzlez.view.common.PaginatorView
|
||||||
|
geometry.width: 100%
|
||||||
|
+onPageSelect: |
|
||||||
|
~(index) -> {
|
||||||
|
page.index = index;
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ru.m.puzzlez.view;
|
package ru.m.puzzlez.view.common;
|
||||||
|
|
||||||
import haxework.view.data.DataView;
|
import haxework.view.data.DataView;
|
||||||
import haxework.view.form.ButtonView;
|
import haxework.view.form.ButtonView;
|
||||||
Reference in New Issue
Block a user