-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from hawariMuflihMunte/bug-fix-patch
Bug fix patch
- Loading branch information
Showing
3 changed files
with
336 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,108 @@ | ||
class Controller { | ||
/** | ||
* Init Backlog and Presenter classes. | ||
* @param {class} Backlog | ||
* @param {class} Presenter | ||
*/ | ||
constructor(Backlog, Presenter) { | ||
this.backlog = Backlog; | ||
this.presenter = Presenter; | ||
|
||
this.renderList(); | ||
|
||
if ( | ||
this.backlog != null || | ||
this.backlog != undefined && | ||
this.presenter != null || | ||
this.presenter != undefined | ||
) { | ||
const currentLocation = window.location.hash.substring(2); | ||
const removeThirdArgs = currentLocation.split('/'); | ||
const nowLocation = removeThirdArgs[0]; | ||
console.log(`BPC init: ${nowLocation}`); | ||
} else { | ||
console.error('Please initiate Backlog and/or Presenter class!'); | ||
} | ||
} | ||
|
||
addData(data) { | ||
const currentData = this.backlog.getData(); | ||
const checkDuplicateData = currentData.find((_data) => { | ||
return _data.title === data.title; | ||
}); | ||
|
||
if (checkDuplicateData) { | ||
alert('Same data is exists!'); | ||
return false; | ||
} | ||
|
||
this.backlog.addData(data); | ||
this.renderList(); | ||
} | ||
|
||
updateData(id, data) { | ||
this.backlog.updateDataById(id, data); | ||
this.renderDetail(id); | ||
} | ||
|
||
renderList() { | ||
const data = this.backlog.getData(); | ||
this.presenter.renderList(data); | ||
} | ||
|
||
renderDetail(id) { | ||
const data = this.backlog.getDataById(id); | ||
// Debugging purpose-only | ||
// console.log(data); | ||
this.presenter.renderDetail(data); | ||
} | ||
|
||
deleteData(id) { | ||
if (this.backlog.deleteData(id)) { | ||
// Debugging purpose-only | ||
// console.log(this.backlog.getData()); | ||
|
||
return true; | ||
} else { | ||
console.error('Error while deleting data from data storage.'); | ||
} | ||
} | ||
}; | ||
|
||
export default Controller; | ||
import Swal from "sweetalert2"; | ||
|
||
/* eslint-disable max-len */ | ||
class Controller { | ||
/** | ||
* Init Backlog and Presenter classes. | ||
* @param {class} Backlog | ||
* @param {class} Presenter | ||
*/ | ||
constructor(Backlog, Presenter) { | ||
this.backlog = Backlog; | ||
this.presenter = Presenter; | ||
|
||
this.renderList(); | ||
|
||
if ( | ||
this.backlog != null || | ||
(this.backlog != undefined && this.presenter != null) || | ||
this.presenter != undefined | ||
) { | ||
const currentLocation = window.location.hash.substring(2); | ||
const removeThirdArgs = currentLocation.split('/'); | ||
const nowLocation = removeThirdArgs[0]; | ||
console.log(`BPC init: ${nowLocation}`); | ||
} else { | ||
console.error('Please initiate Backlog and/or Presenter class!'); | ||
} | ||
} | ||
|
||
addData(data) { | ||
const currentData = this.backlog.getData(); | ||
const checkDuplicateData = currentData.find((_data) => { | ||
return _data.title === data.title; | ||
}); | ||
|
||
if (checkDuplicateData) { | ||
alert('Same data is exists!'); | ||
return false; | ||
} | ||
|
||
this.backlog.addData(data); | ||
this.renderList(); | ||
} | ||
|
||
updateData(id, data) { | ||
this.backlog.updateDataById(id, data); | ||
this.renderDetail(id); | ||
} | ||
|
||
renderList() { | ||
const data = this.backlog.getData(); | ||
this.presenter.renderList(data); | ||
} | ||
|
||
renderDetail(id) { | ||
const data = this.backlog.getDataById(id); | ||
// Debugging purpose-only | ||
// console.log(data); | ||
this.presenter.renderDetail(data); | ||
} | ||
|
||
deleteData(id) { | ||
if (this.backlog.deleteData(id)) { | ||
// Debugging purpose-only | ||
// console.log(this.backlog.getData()); | ||
|
||
return true; | ||
} else { | ||
console.error('Error while deleting data from data storage.'); | ||
} | ||
} | ||
|
||
searchData() { | ||
const searchBar = document.getElementById('search-bar'); | ||
const searchQuery = (searchBar.value).trim().toLowerCase(); | ||
const data = this.backlog.getData(); | ||
|
||
const renderSearchResult = (result) => { | ||
searchBar.value = ''; | ||
this.presenter.renderList(result); | ||
}; | ||
|
||
if (!searchQuery) { | ||
renderSearchResult(data); | ||
return false; | ||
} | ||
|
||
const searchResult = data.filter((task) => | ||
(task.title.trim().toLowerCase()).includes(searchQuery) | ||
); | ||
|
||
if (searchResult.length === 0) { | ||
Swal.fire({ | ||
icon: 'warning', | ||
title: 'Task Not Found', | ||
text: 'We cannot find the task you are looking for. Perhaps it has been deleted, or you can try to use a different search keyword.' | ||
}); | ||
|
||
renderSearchResult(data); | ||
return false; | ||
} | ||
|
||
renderSearchResult(searchResult); | ||
return true; | ||
} | ||
}; | ||
|
||
export default Controller; |
Oops, something went wrong.
db0e677
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.
Successfully deployed to the following URLs:
tugas-ku – ./
tugas-ku-git-main-hawarimuflihmunte.vercel.app
tugas-ku.vercel.app
tugas-ku-hawarimuflihmunte.vercel.app