-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
task4 #6
Changes from 10 commits
3a941a3
8a881f7
d2df6c4
0ce08f7
e92c880
6133232
f3cbbe1
7f4c6d1
b916184
0039053
b3d56b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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"> | ||
<!--<!–1photo–>--> | ||
<!--<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> | ||
|
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); | ||
} | ||
|
||
function filterAuthor(photoPosts, author) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. почему findByAuthor называется (дословно "отфильтровать авторов") |
||
var result = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Оба замечания выше There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. где значения по умолчанию ? |
||
var resultArray = []; | ||
if (filterConfig === undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Заметка (но зависит от того что ожидается от функции, комментария не напимсано поэтому имею право придраться :) ): выражение вида if (filterConfig === undefined) { - явно хотим убедится что не определено |
||
return photoPosts.sort(compareDate).slice(skip, skip + top); | ||
} else { | ||
resultArray = photoPosts.sort(compareDate).slice(skip, skip + top); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. что-то мне подсказывает, что это надо делать после фильтров |
||
if (filterConfig.author !== undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. смотри, это как минимум не item а index |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Логика не соответствует той которая прописана в задании. |
||
if (validatePhotoPost(objectPhotoPost)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. я могу ошибаться, но что-то мне подсказывает что это плохая идея т.к не все поля обязательны There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. лучше пересмотри эту фуннкцию на паре |
||
if (!objectPhotoPost) { | ||
return false; | ||
} | ||
if (id === undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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']}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А вот и не работает оно так :) |
||
getPhotoPost('1'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а как использовать этот модуль ? |
||
|
||
)(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
откуда опять копипастим чужие неточности ? (вопрос риторический, я уже видел откуда)
Скобки не нужны.