Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task4 #6

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitignore

This file was deleted.

Binary file added UI/images/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/101.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/102.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/103.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/11.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/13.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/14.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/15.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/16.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/16_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/17.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/18.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/19.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/19_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/19_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/1_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/20.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/21.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/22.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/images/5_1.jpg
Binary file added UI/images/6.jpg
Binary file added UI/images/7.jpg
Binary file added UI/images/7_1.jpg
Binary file added UI/images/8.jpg
Binary file added UI/images/9.jpg
Binary file added UI/images/body.jpg
Binary file added UI/images/delete.png
Binary file added UI/images/edit.png
Binary file added UI/images/email.png
Binary file added UI/images/heart1.png
Binary file added UI/images/insta.png
Binary file added UI/images/search.png
Binary file added UI/images/vk.png
77 changes: 77 additions & 0 deletions UI/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Marshmallows</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<div class="logo">Marshmallows</div>
<div class="menu">
<a href="index.html" class="home">Home</a>
<form action="" method="get" class="search">
<!--1search-->
<input type="text" placeholder=" search by date...">
<!--2search-->
<input type="text" placeholder=" search by name...">
<!--3search-->
<input type="text" list="hashTag" placeholder=" search by hashTag...">
<datalist id="hashTag">
<option>#nature</option>
<option>#food</option>
<option>#coffe</option>
<option>#flowers</option>
</datalist>

<button type="submit" class="button_search"><img src="images/search.png"/></button>
</form>
<a href="" class="sign_out">Sign out</a>
</div>
</header>
<main>
<div class="site_content">
<!--&lt;!&ndash;1photo&ndash;&gt;-->
<!--<div class="photo_post">-->
<!--<div class="post">-->
<!--<div class="image_name_date">-->
<!--<img class="post_image" src="images/103.png"/>-->
<!--<p class="name">Murashko Yuliya</p>-->
<!--<p class="date_post">06.03.2018</p>-->
<!--</div>-->
<!--</div>-->
<!--<img class="photo" src="images/1_1.jpg">-->
<!--<div class="entry">-->
<!--<p class="description">Text...</p>-->
<!--<p class="hashTag">#coffe</p>-->
<!--<div class="like"> <p>Like: </p><p>author1, author2</p>-->
<!--</div>-->
<!--</div>-->
<!--<button type="button" class="put_like"><img src="images/heart1.png" alt="like"/></button>-->
<!--</div>-->

<!--<button type="button" class="download"><b>...</b></button>-->

</div>
<div class="avatar">
<img class="avatar_image" src="images/101.png"/>
<div class="name">
<p><b>Adamskaya Yuliya</b></p>
<a href=""><i>Add post</i></a>
<div class="line"></div>
</div>
</div>
</main>
<footer>
<div class="logo_footer">Marshmallows</div>
<div class="footer_icon">
<button type="button" class="vk"><img src="images/vk.png" alt="vk"/></button>
<button type="button" class="email"><img src="images/email.png" alt="email"/></button>
<button type="button" class="insta"><img src="images/insta.png" alt="instagram"/></button>
</div>
<p class="data">Adamskaya Yuliya 2 course 6 group<br>03.03.2018</p>
</footer>
<script src="DOM.js"></script>
</body>
</html>

282 changes: 282 additions & 0 deletions UI/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
var photoPosts = [{
id: '1',
description: 'Text',
createdAt: new Date('2018-03-01T23:00:00'),
author: 'Adamskaya Yuliya',
photoLink: 'images/1.jpg',
hashTag: ['#hashtag_1'],
like: ["author1", "author2"]
}, {
id: '2',
description: 'Text',
createdAt: new Date('2018-02-23T23:00:00'),
author: 'Murashko Yuliya',
photoLink: 'images/2.jpg',
hashTag: ['#hashTag'],
like: ["author1"]
}, {
id: '3',
description: 'Text',
createdAt: new Date('2018-02-28T23:00:00'),
author: 'Ambrosyonok Marina',
photoLink: 'images/3.jpg',
hashTag: ['#hashtag_1'],
like: ["author2"]
}, {
id: '4',
description: 'Text',
createdAt: new Date('2018-02-27T23:00:00'),
author: 'Adamskaya Yuliya',
photoLink: 'images/4.jpg',
hashTag: ['#hashtag_1'],
like: ["author1", "author2", "author3"]
}, {
id: '5',
description: 'Text',
createdAt: new Date('2018-02-20T23:00:00'),
author: 'Adamskaya Yuliya',
photoLink: 'images/5.jpg',
hashTag: ['#hashtag_2'],
like: ["author1", "author2"]
}, {
id: '6',
description: 'Text',
createdAt: new Date('2018-02-23T23:00:00'),
author: 'Ambrosyonok Marina',
photoLink: 'images/6.jpg',
hashTag: ['#hashtag_10'],
like: ["author1", "author2"]
}, {
id: '7',
description: 'Text',
createdAt: new Date('2018-02-23T23:00:00'),
author: 'Adamskaya Yuliya',
photoLink: 'images/7.jpg',
hashTag: ['#hashTag'],
like: ["author3"]
}, {
id: '8',
description: 'Text',
createdAt: new Date('2018-02-23T23:00:00'),
author: 'Murashko Yuliya',
photoLink: 'images/8.jpg',
hashTag: ['#hashtag_1'],
like: ["author2"]
}, {
id: '9',
description: 'Text',
createdAt: new Date('2018-02-23T23:00:00'),
author: 'Adamskaya Yuliya',
photoLink: 'images/9.jpg',
hashTag: ['#hashtag_11'],
like: ["author1", "author3"]
}, {
id: '10',
description: 'Text',
createdAt: new Date('2018-02-23T23:00:00'),
author: 'Adamskaya Yuliya',
photoLink: 'images/10.jpg',
hashTag: ['#hashtag_5'],
like: ["author1", "author2"]
}, {
id: '11',
description: 'Text',
createdAt: new Date('2018-03-01T23:00:00'),
author: 'Adamskaya Yuliya',
photoLink: 'images/11.jpg',
hashTag: ['#hashtag_1'],
like: ["author1", "author2"]
}, {
id: '12',
description: 'Text',
createdAt: new Date('2018-02-23T23:00:00'),
author: 'Murashko Yuliya',
photoLink: 'images/12.jpg',
hashTag: ['#hashTag'],
like: ["author1"]
}, {
id: '13',
description: 'Text',
createdAt: new Date('2018-02-28T23:00:00'),
author: 'Ambrosyonok Marina',
photoLink: 'images/13.jpg',
hashTag: ['#hashtag_1'],
like: ["author2"]
}, {
id: '14',
description: 'Text',
createdAt: new Date('2018-02-27T23:00:00'),
author: 'Adamskaya Yuliya',
photoLink: 'images/14.jpg',
hashTag: ['#hashtag_1'],
like: ["author1", "author2", "author3"]
}, {
id: '15',
description: 'Text',
createdAt: new Date('2018-02-20T23:00:00'),
author: 'Adamskaya Yuliya',
photoLink: 'images/15.jpg',
hashTag: ['#hashtag_2'],
like: ["author1", "author2"]
}, {
id: '16',
description: 'Text',
createdAt: new Date('2018-02-23T23:00:00'),
author: 'Ambrosyonok Marina',
photoLink: 'images/16.jpg',
hashTag: ['#hashtag_10'],
like: ["author1", "author2"]
}, {
id: '17',
description: 'Text',
createdAt: new Date('2018-02-23T23:00:00'),
author: 'Adamskaya Yuliya',
photoLink: 'images/17.jpg',
hashTag: ['#hashTag'],
like: ["author3"]
}, {
id: '18',
description: 'Text',
createdAt: new Date('2018-02-23T23:00:00'),
author: 'Murashko Yuliya',
photoLink: 'images/18.jpg',
hashTag: ['#hashtag_1'],
like: ["author2"]
}, {
id: '19',
description: 'Text',
createdAt: new Date('2018-02-23T23:00:00'),
author: 'Adamskaya Yuliya',
photoLink: 'images/19.jpg',
hashTag: ['#hashtag_11'],
like: ["author1", "author3"]
}, {
id: '20',
description: 'Text',
createdAt: new Date('2018-02-23T23:00:00'),
author: 'Adamskaya Yuliya',
photoLink: 'images/20.jpg',
hashTag: ['#hashtag_5'],
like: ["author1", "author2"]
}];

var module = (function () {
function compareDate(a, b) {
return (a.createdAt) - (b.createdAt);
}

function getPhotoPosts(skip, top, filterConfig) {
skip = skip || 0;
top = top || 10;
if (filterConfig === undefined) {
return photoPosts.sort(compareDate).slice(skip, skip + top);
} else {
if (filterConfig.author !== undefined) {
photoPosts = photoPosts.filter((element) => element.author === filterConfig.author);
}
if (filterConfig.hashTag !== undefined) {
photoPosts = photoPosts.filter((element) => element.hashTag === filterConfig.hashTag);
}
return photoPosts.sort(compareDate).slice(skip, skip + top);
}
}

function getPhotoPost(id) {
return photoPosts.find((element) => element.id === id);
}

function validatePhotoPost(photoPost) {
if (typeof(photoPost.id) !== "string" || typeof(photoPost.author) !== "string" || typeof(photoPost.description) !== "string"
|| typeof(photoPost.photoLink) !== "string") {
return false;
}
if (photoPost.id.trim() === "" || photoPost.author.trim() === "" || photoPost.description.trim() === "" || photoPost.photoLink.trim() === ""
|| photoPost.hashTag.length === 0 || photoPost.like.length === 0) {
return false;
}
for (var index = 0; index < photoPost.hashTag.length; index++) {
if (typeof(photoPost.hashTag[index]) !== "string" || photoPost.hashTag[index].trim() === "") {
return false;
}
}

for (var index = 0; index < photoPost.like.length; index++) {
if (typeof(photoPost.like[index]) !== "string" || photoPost.like[index].trim() === "") {
return false;
}
}

if (!photoPost.createdAt instanceof Date) {
return false;
}
return true;
}

function removePhotoPost(id) {
var index = photoPosts.findIndex((element) => element.id === id);
if (index) {
photoPosts = photoPosts.splice(index, 1);
return true;
} else {
return false;
}
}

function addPhotoPost(objectPhotoPost) {
if (validatePhotoPost(objectPhotoPost)) {
photoPosts.push(objectPhotoPost);
return true;
}
return false;
}

function editPhotoPost(id, objectPhotoPost) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Логика не соответствует той которая прописана в задании.

if (!objectPhotoPost) {
return false;
}
if (id === undefined || typeof id !== 'string') {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeof id !== 'string' этого будет достаточно

return false;
}
var index = photoPosts.findIndex((element) => element.id === id);

var post = photoPosts[index];
if (objectPhotoPost.photoLink !== undefined && objectPhotoPost.photoLink !== 0) {
post.photoLink = objectPhotoPost.photoLink;
}
if (objectPhotoPost.description !== undefined && objectPhotoPost.description !== 0 && objectPhotoPost.description.length < 200) {

post.description = objectPhotoPost.description;
}
if (objectPhotoPost.hashTag !== undefined && objectPhotoPost.hashTag.length > 0) {

post.hashTag = objectPhotoPost.hashTag;
}
console.log(post);
return true;

}

return {
getPhotoPosts: getPhotoPosts,
removePhotoPost: removePhotoPost,
editPhotoPost: editPhotoPost,
addPhotoPost: addPhotoPost,
getPhotoPost: getPhotoPost
}
}
)
();
console.log(module.getPhotoPosts(0, 10));
console.log(module.getPhotoPosts(0, 10, {author: "Adamskaya Yuliya"}));
console.log(module.getPhotoPost('9'));
console.log(module.editPhotoPost('1', {hashTag: ['#hashtag_1', '#hashtag_8']}));
console.log(module.addPhotoPost({
id: '21',
description: 'Text',
createdAt: new Date('2018-02-23T21:00:00'),
author: 'Adamskaya Yuliya',
photoLink: 'images/21.jpg',
hashTag: ['#hashtag_1', '#hashtag_2'],
like: ['author21']
}));
console.log(module.removePhotoPost('4'));
Loading