Commit ae9b1e72 authored by camilo higuita's avatar camilo higuita

sync tags with albums now working #22

parent 8c61bb8d
......@@ -3,12 +3,14 @@ var Query = {
allPics : "select * from images order by strftime(\"%s\", addDate) desc",
picLikeUrl_ : "select * from images where url like \"%1%\" ",
albumTags_ : "select * from albums_tags where album = \"%1\"",
picTags_ : "select * from images_tags where url = \"%1\"",
allTags : "select * from tags",
allAlbums : "select * from albums order by strftime(\"%s\", addDate) desc",
allAlbumPics_ : "select distinct i.* from images i inner join images_tags it on it.url = i.url inner join albums_tags at on at.tag = it.tag where at.album = \"%1\" union select i.* from images_albums ia inner join images i on i.url = ia.url where ia.album = \"%1\"",
albumPics_ : "select i.* from images_albums ia inner join images i on i.url = ia.url where ia.album = \"%1\" order by strftime(\"%s\", ia.addDate) desc",
albumPicsTags_ : "select i.* from images i inner join images_tags it on it.url = i.url inner join albums_tags at on at.tag = it.tag where at.album = \"%1\"",
favPics: "select * from images where fav = 1",
recentPics: "select * from images order by strftime(\"%s\", addDate) desc limit 50"
......
......@@ -142,12 +142,29 @@ bool DBActions::picTag(const QString &tag, const QString &url)
return this->insert(PIX::TABLEMAP[PIX::TABLE::IMAGES_TAGS], taggedPic);
}
bool DBActions::albumTag(const QString &tag, const QString &album)
{
this->addTag(tag);
QVariantMap taggedAlbum
{
{PIX::KEYMAP[PIX::KEY::ALBUM], album},
{PIX::KEYMAP[PIX::KEY::TAG], tag}
};
return this->insert(PIX::TABLEMAP[PIX::TABLE::ALBUMS_TAGS], taggedAlbum);
}
bool DBActions::removePicTag(const QString &tag, const QString &url)
{
PIX::DB tagMap {{PIX::KEY::URL, url}, {PIX::KEY::TAG, tag}};
return this->remove(PIX::TABLEMAP[PIX::TABLE::IMAGES_TAGS], tagMap);
}
bool DBActions::removeAlbumTag(const QString &tag, const QString &album)
{
PIX::DB tagMap {{PIX::KEY::TAG, tag}, {PIX::KEY::ALBUM, album}};
return this->remove(PIX::TABLEMAP[PIX::TABLE::ALBUMS_TAGS], tagMap);
}
bool DBActions::addAlbum(const QString &album)
{
QVariantMap albumMap
......
......@@ -23,7 +23,9 @@ class DBActions : public DB
Q_INVOKABLE bool addTag(const QString &tag);
Q_INVOKABLE bool picTag(const QString &tag, const QString &url);
Q_INVOKABLE bool albumTag(const QString &tag, const QString &album);
Q_INVOKABLE bool removePicTag(const QString &tag, const QString &url);
Q_INVOKABLE bool removeAlbumTag(const QString &tag, const QString &album);
Q_INVOKABLE bool addAlbum(const QString &album);
Q_INVOKABLE bool picAlbum(const QString &album, const QString &url);
......
......@@ -63,6 +63,8 @@ namespace PIX
ALBUMS,
IMAGES_TAGS,
IMAGES_ALBUMS,
ALBUMS_TAGS,
IMAGES_NOTES,
ALL,
NONE
};
......@@ -74,6 +76,8 @@ namespace PIX
{TABLE::IMAGES,"images"},
{TABLE::IMAGES_TAGS,"images_tags"},
{TABLE::IMAGES_ALBUMS,"images_albums"},
{TABLE::ALBUMS_TAGS,"albums_tags"},
{TABLE::IMAGES_NOTES,"images_notes"},
{TABLE::TAGS,"tags"}
};
......
......@@ -9,7 +9,8 @@ Item
property alias tagsList : tagsList
signal addClicked()
signal tagRemovedClicked(int index)
RowLayout
{
......@@ -20,11 +21,7 @@ Item
iconName: "list-add"
onClicked:
{
tagsDialog.picUrl = pixViewer.currentPic.url
tagsDialog.open()
}
onClicked: addClicked()
}
TagList
......@@ -35,18 +32,7 @@ Item
Layout.fillHeight: true
Layout.fillWidth: true
onTagRemoved: if(pix.removePicTag(tagsList.model.get(index).tag, pixViewer.currentPic.url))
tagsList.model.remove(index)
Label
{
height: parent.height
width: parent.width
text: qsTr("Add tags...")
opacity: 0.5
visible: tagsList.count === 0
font.pointSize: fontSizes.default
}
onTagRemoved: tagRemovedClicked(index)
}
}
}
import QtQuick 2.0
import QtQuick.Controls 2.2
import "../../../db/Query.js" as Q
ListView
......@@ -8,6 +10,16 @@ ListView
spacing: contentMargins
signal tagRemoved(int index)
Label
{
height: parent.height
width: parent.width
text: qsTr("Add tags...")
opacity: 0.7
visible: count === 0
font.pointSize: fontSizes.default
}
model: ListModel{}
delegate: TagDelegate
......@@ -21,12 +33,10 @@ ListView
}
}
function populate(url)
function populate(query)
{
console.log("trying ot get tag for ", Q.Query.picTags_.arg(url))
model.clear()
var tags = pix.get(Q.Query.picTags_.arg(url))
var tags = pix.get(query)
if(tags.length > 0)
for(var i in tags)
......
......@@ -52,7 +52,8 @@ PixPopup
function addToAlbum(album)
{
if(pix.picAlbum(album, picUrl))
var albumExists = pix.checkExistance("albums", "album", album)
if(pix.picAlbum(album, picUrl) && !albumExists)
albumsView.albumsGrid.model.append({album : album})
close()
}
......
......@@ -37,8 +37,10 @@ PixPopup
function addAlbum()
{
if (pix.addAlbum(albumText.text))
albumCreated(albumText.text)
if(!pix.checkExistance("albums", "album", albumText.text))
if (pix.addAlbum(albumText.text))
albumCreated(albumText.text)
albumText.clear()
close()
}
......
......@@ -10,11 +10,15 @@ PixPopup
{
padding: contentMargins*2
property string picUrl : ""
property string url : ""
onOpened: populate()
signal albumTagged(string tag)
signal picTagged(string tag)
signal tagsAdded(var tags)
property bool forAlbum : false
ColumnLayout
{
......@@ -71,33 +75,48 @@ PixPopup
}
}
Button
{
text: qsTr("Add")
Layout.alignment: Qt.AlignRight
onClicked: addTags(picUrl)
onClicked: setTags()
}
}
function addTags(url)
function setTags()
{
var tags = []
for(var i = 0; i < tagListComposer.model.count; i++)
tags.push(tagListComposer.model.get(i))
tagsAdded(tags)
}
function addTagsToPic(url, tags)
{
if(tags.length > 0)
for(i in tags)
for(var i in tags)
{
if(PIX.addTag(tags[i].tag, picUrl))
if(PIX.addTagToPic(tags[i].tag, url))
picTagged(tags[i].tag)
}
close()
}
function addTagsToAlbum(url, tags)
{
if(tags.length > 0)
for(var i in tags)
{
if(PIX.addTagToAlbum(tags[i].tag, url))
albumTagged(tags[i].tag)
}
close()
}
function populate()
{
tagsList.model.clear()
......@@ -107,6 +126,8 @@ PixPopup
for(var i in tags)
tagsList.model.append(tags[i])
tagListComposer.populate(picUrl)
tagListComposer.populate(forAlbum ? Q.Query.albumTags_.arg(url) :
Q.Query.picTags_.arg(url))
}
}
......@@ -6,7 +6,9 @@ import QtQuick.Layouts 1.3
GridView
{
id: albumsGridRoot
property int gridSize : 64
property string currentAlbum : ""
signal albumClicked(int index)
......
......@@ -5,6 +5,9 @@ import "../../../db/Query.js" as Q
import "../../../widgets/views/Viewer/Viewer.js" as VIEWER
import "../../dialogs/Albums"
import "../../../widgets/custom/TagBar"
import "../../dialogs/Tags"
PixPage
{
......@@ -12,13 +15,9 @@ PixPage
headerbarExit: stackView.currentItem === picsView
headerbarExitIcon: "go-previous"
headerbarTitle: stackView.currentItem === picsView ? "undefined" : albumGrid.count+qsTr(" Albums")
headerbarTitle: stackView.currentItem === picsView ? albumGrid.currentAlbum : albumGrid.count+qsTr(" Albums")
onExit:
{
stackView.pop(albumGrid)
headerbarTitle = "Albums"
}
onExit: stackView.pop(albumGrid)
headerBarRight: [
......@@ -39,6 +38,34 @@ PixPage
}
]
footer: ToolBar
{
id: footerBar
position: ToolBar.Footer
visible: false
TagBar
{
id: tagBar
anchors.fill: parent
onAddClicked:
{
tagsDialog.url = albumGrid.currentAlbum
tagsDialog.open()
}
onTagRemovedClicked: if(pix.removeAlbumTag(tagsList.model.get(index).tag, albumGrid.currentAlbum))
tagsList.model.remove(index)
}
}
TagsDialog
{
id: tagsDialog
forAlbum: true
onTagsAdded: addTagsToAlbum(url, tags)
onAlbumTagged: tagBar.tagsList.model.insert(0, {"tag": tag})
}
NewAlbumDialog
{
id: newAlbumDialog
......@@ -95,8 +122,10 @@ PixPage
function filter(album)
{
headerbarTitle = album
albumGrid.currentAlbum = album
picsView.clear()
tagBar.tagsList.model.clear()
footerBar.visible = false
switch(album)
{
......@@ -107,9 +136,11 @@ PixPage
populateAlbum(Q.Query.recentPics)
break
default:
populateAlbum(Q.Query.albumPics_.arg(album))
break
populateAlbum(Q.Query.allAlbumPics_.arg(album))
footerBar.visible = true
tagBar.tagsList.populate(Q.Query.albumTags_.arg(album))
break
}
}
......
......@@ -8,7 +8,12 @@ function refreshViews()
albumsView.populate()
}
function addTag(tag, url)
function addTagToPic(tag, url)
{
return pix.picTag(tag, url)
}
function addTagToAlbum(tag, url)
{
return pix.albumTag(tag, url)
}
......@@ -59,13 +59,21 @@ PixPage
{
id: tagBar
anchors.fill: parent
onAddClicked:
{
tagsDialog.url = currentPic.url
tagsDialog.open()
}
onTagRemovedClicked: if(pix.removePicTag(tagsList.model.get(index).tag, pixViewer.currentPic.url))
tagsList.model.remove(index)
}
}
TagsDialog
{
id: tagsDialog
forAlbum: false
onTagsAdded: addTagsToPic(url, tags)
onPicTagged: tagBar.tagsList.model.insert(0, {"tag": tag})
}
......
.import "../Pix.js" as PIX
.import "../../../db/Query.js" as Q
function open(model, index)
......@@ -17,7 +18,7 @@ function view(index)
{
pixViewer.currentPic = pixViewer.picContext[index]
pixViewer.currentPicFav = pix.isFav(pixViewer.currentPic.url)
pixViewer.tagBar.tagsList.populate(pixViewer.currentPic.url)
pixViewer.tagBar.tagsList.populate(Q.Query.picTags_.arg(pixViewer.currentPic.url))
root.title = pixViewer.currentPic.title
}
......
import QtQuick 2.0
import QtQuick.Controls 2.2
Image {
Image
{
height: parent.height
width: parent.width
source: "file://"+currentPic.url
fillMode: Image.PreserveAspectFit
cache: true
asynchronous: true
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment