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 10 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>

305 changes: 305 additions & 0 deletions UI/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
(function () {
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"]
}];

function compareDate(a, b) {
return (a.createdAt) - (b.createdAt);
Copy link

Choose a reason for hiding this comment

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

откуда опять копипастим чужие неточности ? (вопрос риторический, я уже видел откуда)
Скобки не нужны.

}

function filterAuthor(photoPosts, author) {
Copy link

Choose a reason for hiding this comment

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

почему findByAuthor называется (дословно "отфильтровать авторов")

var result = [];
Copy link

Choose a reason for hiding this comment

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

for (var item in photoPosts) {
if (photoPosts[item].author === author) {
result.push(photoPosts[item]);
}
}
return result;
}

function filterHashtag(photoPosts, hashtag) {
Copy link

Choose a reason for hiding this comment

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

Оба замечания выше

Copy link

Choose a reason for hiding this comment

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

var result = [];
for (var item in photoPosts) {
if (photoPosts[item].hashTag === hashtag) {
result.push(photoPosts[item]);
}
}
return result;
}

function getPhotoPosts(skip, top, filterConfig) {
Copy link

Choose a reason for hiding this comment

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

где значения по умолчанию ?

var resultArray = [];
if (filterConfig === undefined) {
Copy link

Choose a reason for hiding this comment

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

Заметка (но зависит от того что ожидается от функции, комментария не напимсано поэтому имею право придраться :) ):
В таких ситуациях 2 подхода:
Либо мы проверяем просто чо переменная "похожа на правду":
if (filterConfig) {...} или явно if (!!filterConfig) {}
в обоих случаях filterConfig будет приведен к типу Boolean
Либо мы проверяем что к нам пришло что-то похожее на то что мы ожидаем:
if (typeof filterConfig === 'object') {...}

выражение вида if (filterConfig === undefined) { - явно хотим убедится что не определено

return photoPosts.sort(compareDate).slice(skip, skip + top);
} else {
resultArray = photoPosts.sort(compareDate).slice(skip, skip + top);
Copy link

Choose a reason for hiding this comment

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

что-то мне подсказывает, что это надо делать после фильтров

if (filterConfig.author !== undefined) {
Copy link

Choose a reason for hiding this comment

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

а мы точно сначала урезаем а потом фильтруем, не наоборот ? ))

resultArray = filterAuthor(resultArray, filterConfig.author);
}
if (filterConfig.hashTag !== undefined) {
resultArray = filterHashtag(resultArray, filterConfig.hashTag);
}
}
return resultArray;
}

function getPhotoPost(id) {
for (var item in photoPosts) {
Copy link

Choose a reason for hiding this comment

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

if (photoPosts[item].id === id) {
return photoPosts[item];
}
}
}

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 item in photoPost.hashTag) {
Copy link

Choose a reason for hiding this comment

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

смотри, это как минимум не item а index
for .. in впринципе лучше не использовать
есть обычный for, forEach, for .. of

if (typeof(photoPost.hashTag[item]) !== "string" || photoPost.hashTag[item].trim() === "") {
return false;
}
}

for (var item in photoPost.like) {
if (typeof(photoPost.like[item]) !== "string" || photoPost.like[item].trim() === "") {
return false;
}
}

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

function removePhotoPost(id) {
for (var item in photoPosts) {
if (photoPosts[item].id === id) {
photoPosts = photoPosts.splice(item, 1);
return true;
}
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 (validatePhotoPost(objectPhotoPost)) {
Copy link

Choose a reason for hiding this comment

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

я могу ошибаться, но что-то мне подсказывает что это плохая идея т.к не все поля обязательны

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) {
Copy link

Choose a reason for hiding this comment

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

где-то я уже это видел

return false;
}
for (var item in photoPosts) {
if (photoPosts[item].id === id) {
var post = photoPosts[item];
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;
}
photoPosts[item] = post;
console.log(post);
return true;
}
}
}
return false;
}

console.log(getPhotoPosts(0, 10));
Copy link

Choose a reason for hiding this comment

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

ттесыт должны быть во вне

console.log(getPhotoPosts(0, 10, {hashTag: "#hashtag_1", author: "Adamskaya Yuliya"}));
console.log(getPhotoPost("8"));
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']
});
removePhotoPost('4');
editPhotoPost('1', {hashTag: ['#hashtag_1', '#hashtag_8']});
Copy link

Choose a reason for hiding this comment

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

А вот и не работает оно так :)

getPhotoPost('1');
}
Copy link

Choose a reason for hiding this comment

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

а как использовать этот модуль ?


)();
Loading