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 9 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/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/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/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/6.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/7.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/8.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/9.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/delete.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/edit.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/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
438 changes: 438 additions & 0 deletions UI/index.html

Large diffs are not rendered by default.

304 changes: 304 additions & 0 deletions UI/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,304 @@
(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 i in photoPosts) {
if (photoPosts[i].author === author) {
result.push(photoPosts[i]);
}
}
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 i in photoPosts) {
if (photoPosts[i].hashTag === hashtag) {
result.push(photoPosts[i]);
}
}
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 i 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[i].id === id) {
return photoPosts[i];
}
}
}

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){
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 i in photoPost.hashTag){
if(typeof(photoPost.hashTag[i]) !== "string" || photoPost.hashTag[i].trim() === "") {
Copy link

Choose a reason for hiding this comment

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

Мне кажется не надо так прям строго... ну это ладно.
PS: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array/some

return false;
}
}

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

if(!photoPost.createdAt instanceof Date){
return false;
}
return true;
}
function removePhotoPost(id) {
for (var i in photoPosts) {
Copy link

Choose a reason for hiding this comment

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

https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex
и будут всего 3 понятные строчки...

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