diff --git a/MobileClient/QtProject/src/SpotViewDelegate.qml b/MobileClient/QtProject/src/SpotViewDelegate.qml index 659c8b6..56ce7d8 100644 --- a/MobileClient/QtProject/src/SpotViewDelegate.qml +++ b/MobileClient/QtProject/src/SpotViewDelegate.qml @@ -3,7 +3,7 @@ import QtQuick 2.1 import QtQuick.Controls 1.0 -// Project imports ------------------------- +// Project qml imports --------------------- import "qrc:/widgets" Item { @@ -11,7 +11,6 @@ Item { width: parent.width height: rectangle_Top.height + image_Picture.height - + text_SpotDescription.height signal userClicked signal spotClicked @@ -22,11 +21,17 @@ Item { width: parent.width height: 40 color: "#aaaaaa" + + // Username Text{ id: text_Username width: parent.width / 2 height: parent.height / 2 - text: role_UserUsername + + text: role_UserUsername + color: hc_Application.color_TextLink() + font.bold: true + MouseArea { anchors.fill: parent onClicked: { @@ -34,29 +39,39 @@ Item { } } } + + // Time Text { anchors.top: parent.top anchors.left: text_Username.right width: text_Username.width height: text_Username.height horizontalAlignment: Text.AlignRight + text: role_PictureCreated } + + // Title Text { id: text_SpotName anchors.top: text_Username.bottom width: parent.width height: text_Username.height horizontalAlignment: Text.AlignHCenter + text: role_SpotName } } + + // Picture CachedPicture { id: image_Picture anchors.top: rectangle_Top.bottom width: parent.width height: width + sourceUrl: role_PictureUrl + MouseArea { anchors.fill: parent onClicked: { @@ -64,11 +79,4 @@ Item { } } } - Text { - id: text_SpotDescription - anchors.top: image_Picture.bottom - width: parent.width - height: 40 - text: role_SpotDescription - } } diff --git a/MobileClient/QtProject/src/cpp/HelperClasses/ApplicationHelper.h b/MobileClient/QtProject/src/cpp/HelperClasses/ApplicationHelper.h index fd4d778..5d75f0c 100644 --- a/MobileClient/QtProject/src/cpp/HelperClasses/ApplicationHelper.h +++ b/MobileClient/QtProject/src/cpp/HelperClasses/ApplicationHelper.h @@ -52,6 +52,9 @@ public slots: bool developmentMode() const; void setDevelopmentMode(bool developmentMode); + // Colors + QString color_TextLink() const { return "#265f8b"; } + private slots: void slot_CommandGetCurrentClientVersion_Finished(const WebApiError &error); diff --git a/MobileClient/QtProject/src/cpp/WebApi/Picture.cpp b/MobileClient/QtProject/src/cpp/WebApi/Picture.cpp index 8ce8853..8bddd80 100644 --- a/MobileClient/QtProject/src/cpp/WebApi/Picture.cpp +++ b/MobileClient/QtProject/src/cpp/WebApi/Picture.cpp @@ -30,20 +30,6 @@ Picture::Picture(QObject *parent) : { } -Picture::Picture(const Picture &other) : - QObject(other.parent()), - m_Id (other.m_Id), - m_IdUser (other.m_IdUser), - m_IdSpot (other.m_IdSpot), - m_Url (other.m_Url), - m_Username (other.m_Username), - m_SpotName (other.m_SpotName), - m_SpotDescription(other.m_SpotDescription), - m_Created (other.m_Created), - m_WebApiCommand (NULL) -{ - -} Picture::Picture(int id, int idUser, @@ -118,7 +104,7 @@ QVariant Picture::pictureRole(PictureRoles role) const return m_SpotDescription; break; case Role_PictureCreated: - return m_Created; + return createdText(); break; case Role_PictureUrl: return m_Url; @@ -144,4 +130,25 @@ QHash Picture::roleNames() return roles; } +//----------------------------------------------------------------------------------------------------------------------------- + +QString Picture::createdText() const +{ + int elapseTime = m_Created.msecsTo(QDateTime::currentDateTime()) / 1000; + + if(elapseTime < 60) + return tr("%1s").arg(elapseTime); + + if(elapseTime < 60 * 60) + return tr("%1m").arg(elapseTime / 60); + + if(elapseTime < 60 * 60 * 24) + return tr("%1h").arg(elapseTime / (60 * 60)); + + if(elapseTime < 60 * 60 * 24 * 7) + return tr("%1d").arg(elapseTime / (60 * 60 * 24)); + + return tr("%1w").arg(elapseTime / (60 * 60 * 24 * 7)); +} + diff --git a/MobileClient/QtProject/src/cpp/WebApi/Picture.h b/MobileClient/QtProject/src/cpp/WebApi/Picture.h index 25d528a..8417569 100644 --- a/MobileClient/QtProject/src/cpp/WebApi/Picture.h +++ b/MobileClient/QtProject/src/cpp/WebApi/Picture.h @@ -41,12 +41,12 @@ class Picture : public QObject }; explicit Picture(QObject *parent = 0); - explicit Picture(const Picture &other); explicit Picture(int id, int idUser, int idSpot, QString url, QString username, QString name, - QString description, QDateTime created, + QString description, + QDateTime created, QObject *parent = 0); ~Picture(); Picture &operator=(const Picture &other); @@ -59,6 +59,7 @@ class Picture : public QObject QString spotName() const { return m_SpotName; } QString spotDescription() const { return m_SpotDescription; } QDateTime created() const { return m_Created; } + QString createdText() const; void setIdSpot (int idSpot) {m_IdSpot = idSpot;} void setUrl (const QString &url) {m_Url = url;} diff --git a/MobileClient/QtProject/src/cpp/WebApi/Spot.cpp b/MobileClient/QtProject/src/cpp/WebApi/Spot.cpp index 84bfbee..361bc30 100644 --- a/MobileClient/QtProject/src/cpp/WebApi/Spot.cpp +++ b/MobileClient/QtProject/src/cpp/WebApi/Spot.cpp @@ -52,6 +52,22 @@ Spot::Spot(int id, //----------------------------------------------------------------------------------------------------------------------------- +Spot::Spot(QObject *parent) + : QObject(parent), + m_Id (-1), + m_Name (""), + m_Description (""), + m_Latitude (0.0), + m_Longitude (0.0), + m_Distance_km (0.0), + m_PictureUrl1 (""), + m_PictureUrl2 ("") +{ + +} + +//----------------------------------------------------------------------------------------------------------------------------- + Spot::~Spot() { diff --git a/MobileClient/QtProject/src/cpp/WebApi/Spot.h b/MobileClient/QtProject/src/cpp/WebApi/Spot.h index db2f6ea..fd5a53a 100644 --- a/MobileClient/QtProject/src/cpp/WebApi/Spot.h +++ b/MobileClient/QtProject/src/cpp/WebApi/Spot.h @@ -39,6 +39,7 @@ class Spot : public QObject QString pictureUrl1, QString pictureUrl2, QObject *parent = 0); + explicit Spot(QObject *parent = 0); ~Spot(); QVariant spotRole(SpotRoles role) const; diff --git a/MobileClient/QtProject/src/cpp/main.cpp b/MobileClient/QtProject/src/cpp/main.cpp index 567390c..e6a380e 100644 --- a/MobileClient/QtProject/src/cpp/main.cpp +++ b/MobileClient/QtProject/src/cpp/main.cpp @@ -8,8 +8,10 @@ #include "HelperClasses/PictureCacher.h" #include "WebApi/SpotRepository.h" #include "WebApi/SpotsModel.h" +#include "WebApi/Spot.h" #include "WebApi/PictureRepository.h" #include "WebApi/PicturesModel.h" +#include "WebApi/Picture.h" #include "WebApi/User.h" #include "WebApi/NewsModel.h" #include "WebApi/NearbySpotsModel.h" @@ -58,7 +60,9 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("wa_PictureUploader", &pictureUploader); qmlRegisterType ("PicturesModel", 1, 0, "PicturesModel"); + qmlRegisterType ("Picture", 1, 0, "Picture"); qmlRegisterType ("SpotsModel", 1, 0, "SpotsModel"); + qmlRegisterType ("Spot", 1, 0, "Spot"); qmlRegisterType ("NewsModel", 1, 0, "NewsModel"); qmlRegisterType("NearbySpotsModel", 1, 0, "NearbySpotsModel"); diff --git a/WebSite/Symfony/src/Instaspots/SpotsBundle/Controller/NewsController.php b/WebSite/Symfony/src/Instaspots/SpotsBundle/Controller/NewsController.php index 3a81c21..58d0ca6 100644 --- a/WebSite/Symfony/src/Instaspots/SpotsBundle/Controller/NewsController.php +++ b/WebSite/Symfony/src/Instaspots/SpotsBundle/Controller/NewsController.php @@ -15,38 +15,38 @@ public function indexAction() ->getManager() ->getRepository('InstaspotsSpotsBundle:Picture'); - $pictures = $repository->getNews(); + $pictures = $repository->getPicturesByNewest(); - return $this->render('InstaspotsSpotsBundle:Advert:index.html.twig', + return $this->render('InstaspotsSpotsBundle:Advert:index.html.twig', array('listPictures' => $pictures)); } - + public function downloadAction() { $listPlatforms = array( array('title' => 'Android', 'link' => 'link'), array('title' => 'Source', 'link' => 'https://github.com/domi4484/instaspots') ); - - return $this->render('InstaspotsSpotsBundle:Advert:download.html.twig', + + return $this->render('InstaspotsSpotsBundle:Advert:download.html.twig', array('listPlatforms' => $listPlatforms)); } - + public function viewAction($id) { $repository = $this->getDoctrine() ->getManager() ->getRepository('InstaspotsSpotsBundle:Spot'); - + $spot = $repository->find($id); - + if (null === $spot) { throw new NotFoundHttpException("L'annonce d'id ".$id." n'existe pas."); } return new Response("Affichage de l'annonce d'id : ".$spot->getName()); } - + public function menuAction($limit) { // On fixe en dur une liste ici, bien entendu par la suite @@ -64,4 +64,3 @@ public function menuAction($limit) )); } } - diff --git a/WebSite/Symfony/src/Instaspots/SpotsBundle/Entity/Picture.php b/WebSite/Symfony/src/Instaspots/SpotsBundle/Entity/Picture.php index 4d46390..73bb7ce 100644 --- a/WebSite/Symfony/src/Instaspots/SpotsBundle/Entity/Picture.php +++ b/WebSite/Symfony/src/Instaspots/SpotsBundle/Entity/Picture.php @@ -17,7 +17,7 @@ class Picture * @ORM\JoinColumn(nullable=false) */ private $user; - + /** * @ORM\ManyToOne(targetEntity="Instaspots\SpotsBundle\Entity\Spot", inversedBy="pictures") * @ORM\JoinColumn(nullable=false) @@ -53,20 +53,20 @@ class Picture * @ORM\Column(name="longitude", type="float") */ private $longitude; - + /** * @var bool * * @ORM\Column(name="published", type="boolean") */ private $published = false; - + /** * @ORM\ManyToMany(targetEntity="Instaspots\UserBundle\Entity\User") */ private $likers; - - + + /** * Constructor */ @@ -78,14 +78,14 @@ public function __construct() public function setId($id) { $this->id = $id; - + return $this; } - + /** * Get id * - * @return integer + * @return integer */ public function getId() { @@ -108,13 +108,18 @@ public function setCreated($created) /** * Get created * - * @return \DateTime + * @return \DateTime */ public function getCreated() { return $this->created; } + public function getCreatedISOText() + { + return $this->created->format(DATE_ISO8601); + } + /** * Set latitude * @@ -131,7 +136,7 @@ public function setLatitude($latitude) /** * Get latitude * - * @return float + * @return float */ public function getLatitude() { @@ -154,7 +159,7 @@ public function setLongitude($longitude) /** * Get longitude * - * @return float + * @return float */ public function getLongitude() { @@ -177,7 +182,7 @@ public function setPublished($published) /** * Get published * - * @return boolean + * @return boolean */ public function getPublished() { @@ -200,7 +205,7 @@ public function setUser(\Instaspots\UserBundle\Entity\User $user) /** * Get user * - * @return \Instaspots\UserBundle\Entity\User + * @return \Instaspots\UserBundle\Entity\User */ public function getUser() { @@ -223,7 +228,7 @@ public function setSpot(\Instaspots\SpotsBundle\Entity\Spot $spot) /** * Get spot * - * @return \Instaspots\SpotsBundle\Entity\Spot + * @return \Instaspots\SpotsBundle\Entity\Spot */ public function getSpot() { @@ -263,22 +268,22 @@ public function removeLiker(\Instaspots\UserBundle\Entity\User $liker) /** * Get likers * - * @return \Doctrine\Common\Collections\Collection + * @return \Doctrine\Common\Collections\Collection */ public function getLikers() { return $this->likers; } - + //----------------------------------------------------------------------------------------------------------------------------- - + public function toJson() { $jPicture = array(); $jPicture['id'] = $this->getId(); $jPicture['latitude'] = $this->getLatitude(); $jPicture['longitude' ] = $this->getLongitude(); - $jPicture['created'] = $this->getCreated(); + $jPicture['created'] = $this->getCreatedISOText(); $jPicture['url'] = $this->getUrl(); $jPicture['id_spot' ] = $this->getSpot()->getId(); @@ -288,7 +293,7 @@ public function toJson() $jPicture['id_user'] = $this->getUser()->getId(); $jPicture['username'] = $this->getUser()->getUsername(); - + return $jPicture; } } diff --git a/WebSite/Symfony/src/Instaspots/SpotsBundle/Resources/views/Advert/index.html.twig b/WebSite/Symfony/src/Instaspots/SpotsBundle/Resources/views/Advert/index.html.twig index 87449a8..fedb663 100644 --- a/WebSite/Symfony/src/Instaspots/SpotsBundle/Resources/views/Advert/index.html.twig +++ b/WebSite/Symfony/src/Instaspots/SpotsBundle/Resources/views/Advert/index.html.twig @@ -10,7 +10,7 @@