schermate di configurazione complete: razze disponibili, mio pollaio, registro galline, clienti, backup/ripristino nel formato dell'app Android, lingua a runtime, introduzione e informazioni
- datastore: export/import JSON con le chiavi camelCase dell'app Android (breedSettings/reservations/customers), scorte e ultimo aggiornamento preservati al ripristino - settings: flag 'introduzione vista' - desktop: permesso Documents (dove finisce il backup) - nuovi controlli: tools/check_qml.py (chiavi di traduzione, simboli JS, pagine, componenti) e qmllint nella suite - versione 0.2.0
This commit is contained in:
@@ -0,0 +1,257 @@
|
||||
import QtQuick 2.2
|
||||
import Sailfish.Silica 1.0
|
||||
import "../js/henflow.js" as HF
|
||||
import "../js/i18n.js" as I18N
|
||||
import "../js/catalog.js" as Catalog
|
||||
|
||||
// Scheda di una razza allevata: foto, scheda informativa e registro delle
|
||||
// galline (nome, nascita, eta' in mesi, stato) con interruttore deposizione
|
||||
// ed eliminazione con annulla.
|
||||
Page {
|
||||
id: page
|
||||
allowedOrientations: Orientation.All
|
||||
|
||||
property string breedId: ""
|
||||
property string lang: "en"
|
||||
property bool ready: false
|
||||
property var hens: []
|
||||
|
||||
property string breedName: ""
|
||||
property string breedDescription: ""
|
||||
property string eggColor: ""
|
||||
property int registered: 0
|
||||
property int laying: 0
|
||||
property real daily: 0
|
||||
|
||||
function tr(key, arg) { return I18N.t(key, arg, page.lang) }
|
||||
|
||||
ListModel { id: henModel }
|
||||
|
||||
function reload() {
|
||||
page.lang = I18N.langFor(appSettings.language, Qt.locale().name)
|
||||
|
||||
var breed = Catalog.breedFromId(page.breedId)
|
||||
if (breed) {
|
||||
page.breedName = page.tr(breed.name)
|
||||
page.breedDescription = page.tr(breed.description)
|
||||
page.eggColor = page.tr("egg_color") + ": " + page.tr(breed.eggColor)
|
||||
}
|
||||
|
||||
var setting = null
|
||||
var settings = appData.breedSettings()
|
||||
for (var i = 0; i < settings.length; i++) {
|
||||
if (settings[i].breedId === page.breedId)
|
||||
setting = settings[i]
|
||||
}
|
||||
|
||||
page.hens = (setting && setting.hens) ? setting.hens : []
|
||||
page.registered = page.hens.length
|
||||
page.laying = HF.activeHens({ "hens": page.hens })
|
||||
page.daily = page.laying * HF.eggsPerHenPerDay(Catalog.HF_BREEDS, page.breedId)
|
||||
|
||||
var today = HF.todayMidnight()
|
||||
henList.clear()
|
||||
for (var j = 0; j < page.hens.length; j++) {
|
||||
var hen = page.hens[j]
|
||||
var birth = HF.parseIso(hen.birthDate)
|
||||
var months = birth ? HF.ageInMonths(birth, today) : 0
|
||||
var status
|
||||
if (months >= 6)
|
||||
status = hen.isLaying ? page.tr("status_laying") : page.tr("status_rest")
|
||||
else
|
||||
status = hen.isLaying ? page.tr("status_laying") : page.tr("status_young")
|
||||
|
||||
henList.append({
|
||||
"n": j,
|
||||
"name": hen.name,
|
||||
"birth": page.tr("birth") + ": " + HF.formatDay(hen.birthDate),
|
||||
"age": page.tr("age_months", months),
|
||||
"status": status,
|
||||
"isLaying": hen.isLaying
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Salva il registro delle galline di questa razza.
|
||||
function saveHens(list) {
|
||||
var settings = appData.breedSettings()
|
||||
for (var i = 0; i < settings.length; i++) {
|
||||
if (settings[i].breedId === page.breedId)
|
||||
settings[i].hens = list
|
||||
}
|
||||
appData.saveBreedSettings(settings)
|
||||
page.reload()
|
||||
}
|
||||
|
||||
function toggleHen(index) {
|
||||
var list = page.hens.slice()
|
||||
list[index].isLaying = !list[index].isLaying
|
||||
page.saveHens(list)
|
||||
}
|
||||
|
||||
function deleteHen(index) {
|
||||
var list = page.hens.slice()
|
||||
var hen = list[index]
|
||||
remorse.execute(henList, page.tr("delete"), function () {
|
||||
list.splice(index, 1)
|
||||
page.saveHens(list)
|
||||
}, 4000)
|
||||
}
|
||||
|
||||
function openHen(index) {
|
||||
var hen = (index >= 0 && index < page.hens.length) ? page.hens[index] : null
|
||||
pageStack.push(Qt.resolvedUrl("HenPage.qml"),
|
||||
{ "breedId": page.breedId, "hen": hen })
|
||||
}
|
||||
|
||||
Component.onCompleted: page.reload()
|
||||
|
||||
onStatusChanged: {
|
||||
if (status !== PageStatus.Active)
|
||||
return
|
||||
if (page.ready)
|
||||
page.reload()
|
||||
page.ready = true
|
||||
}
|
||||
|
||||
RemorseItem { id: remorse }
|
||||
|
||||
SilicaListView {
|
||||
id: henList
|
||||
anchors.fill: parent
|
||||
|
||||
header: Column {
|
||||
width: henList.width
|
||||
|
||||
PageHeader { title: page.tr("breed_sheet", page.breedName) }
|
||||
|
||||
Image {
|
||||
x: Theme.horizontalPageMargin
|
||||
width: henList.width - 2 * Theme.horizontalPageMargin
|
||||
height: width / 2
|
||||
source: Catalog.breedFromId(page.breedId)
|
||||
? "file://" + Catalog.breedFromId(page.breedId).asset : ""
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
asynchronous: true
|
||||
}
|
||||
|
||||
Item { width: parent.width; height: Theme.paddingMedium }
|
||||
|
||||
Column {
|
||||
x: Theme.horizontalPageMargin
|
||||
width: henList.width - 2 * Theme.horizontalPageMargin
|
||||
spacing: Theme.paddingSmall
|
||||
|
||||
Label {
|
||||
width: parent.width
|
||||
text: page.breedDescription
|
||||
color: Theme.secondaryColor
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
|
||||
Label {
|
||||
width: parent.width
|
||||
text: page.eggColor
|
||||
color: Theme.secondaryColor
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
truncationMode: TruncationMode.Fade
|
||||
}
|
||||
|
||||
Label {
|
||||
width: parent.width
|
||||
text: page.tr("reg_hens") + ": " + page.registered
|
||||
+ " · " + page.tr("laying_6_months") + ": " + page.laying
|
||||
color: Theme.secondaryColor
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
truncationMode: TruncationMode.Fade
|
||||
}
|
||||
|
||||
Label {
|
||||
width: parent.width
|
||||
text: page.tr("est_prod") + ": " + page.daily.toFixed(1) + " " + page.tr("eggs_per_day")
|
||||
color: Theme.secondaryColor
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
truncationMode: TruncationMode.Fade
|
||||
}
|
||||
}
|
||||
|
||||
Item { width: parent.width; height: Theme.paddingMedium }
|
||||
|
||||
SectionHeader { text: page.tr("hen_registry") }
|
||||
}
|
||||
|
||||
model: henModel
|
||||
|
||||
delegate: ListItem {
|
||||
id: henItem
|
||||
contentHeight: henText.height + Theme.paddingMedium
|
||||
|
||||
menu: ContextMenu {
|
||||
MenuItem {
|
||||
text: page.tr("delete")
|
||||
onClicked: page.deleteHen(index)
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
id: henText
|
||||
x: Theme.horizontalPageMargin
|
||||
y: Theme.paddingMedium
|
||||
width: parent.width - 2 * Theme.horizontalPageMargin - layingSwitch.width
|
||||
- Theme.paddingMedium
|
||||
spacing: Theme.paddingSmall
|
||||
|
||||
Label {
|
||||
width: parent.width
|
||||
text: model.name
|
||||
color: henItem.highlighted ? Theme.highlightColor : Theme.primaryColor
|
||||
truncationMode: TruncationMode.Fade
|
||||
}
|
||||
|
||||
Label {
|
||||
width: parent.width
|
||||
text: model.birth
|
||||
color: Theme.secondaryColor
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
truncationMode: TruncationMode.Fade
|
||||
}
|
||||
|
||||
Label {
|
||||
width: parent.width
|
||||
text: model.age + " · " + model.status
|
||||
color: Theme.secondaryColor
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
truncationMode: TruncationMode.Fade
|
||||
}
|
||||
}
|
||||
|
||||
Switch {
|
||||
id: layingSwitch
|
||||
anchors {
|
||||
right: parent.right
|
||||
rightMargin: Theme.horizontalPageMargin
|
||||
verticalCenter: parent.verticalCenter
|
||||
}
|
||||
checked: model.isLaying
|
||||
onClicked: page.toggleHen(index)
|
||||
}
|
||||
|
||||
onClicked: page.openHen(index)
|
||||
}
|
||||
|
||||
ViewPlaceholder {
|
||||
enabled: henModel.count === 0
|
||||
text: page.tr("no_hens_reg")
|
||||
}
|
||||
|
||||
PullDownMenu {
|
||||
MenuItem {
|
||||
text: page.tr("new_hen")
|
||||
onClicked: page.openHen(-1)
|
||||
}
|
||||
}
|
||||
|
||||
VerticalScrollDecorator {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user