Skip to content

Commit

Permalink
update context delete
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWitcher1991 committed Sep 27, 2023
1 parent e5709a2 commit d7bbb96
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 136 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"bin": "./cli.js",
"private": true,
"expressPort": 8080,
"type": "commonjs",
"basePath": "./dist",
"scripts": {
"test": "jest",
Expand Down
2 changes: 2 additions & 0 deletions src/dev/api.dev.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

'use strict'

console.timeEnd('Launch')
Expand Down
2 changes: 1 addition & 1 deletion src/dev/db/config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"theme":"dark","lang":"ru","FileDeleteNotice":1,"PresetDeleteNotice":1,"ReadSubfolders":1,"ActivePreset":"start"}
{"theme":"dark","lang":"ru","FileDeleteNotice":1,"PresetDeleteNotice":1,"ReadSubfolders":1,"ActivePreset":"9kjs8jhks2ccb4l52sqx"}
2 changes: 1 addition & 1 deletion src/dev/db/db.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"start":{"name":"Базовый","pathFrom":"C:\\Users\\ashot\\OneDrive\\Рабочий стол\\КУРСОВЫЕ РАБОТЫ\\2_КУРС\\Базы данных","pathTo":"C:\\Users\\ashot\\OneDrive\\Рабочий стол\\tmp","typeFiles":"","sizeFiles":"","wordLeft":"","wordRight":"","changed":"","remember":["esp","Свазян"],"regexp":["[А-Яа-яЁё]{4}[-.]\\d{6}[-.]\\d{3}"]}},{"9kjs8jhks2ccb4l52sqx":{"name":"Сети","pathFrom":"C:\\Users\\ashot\\OneDrive\\Рабочий стол\\КУРСОВЫЕ РАБОТЫ\\2_КУРС\\Сети","pathTo":"C:\\Users\\ashot\\OneDrive\\Рабочий стол\\tmp","typeFiles":"","sizeFiles":"","wordLeft":"","wordRight":"","changed":"","remember":[],"regexp":[]}}]
[{"start":{"name":"Базовый","pathFrom":"C:\\Users\\ashot\\OneDrive\\Рабочий стол\\КУРСОВЫЕ РАБОТЫ\\2_КУРС\\Базы данных","pathTo":"C:\\Users\\ashot\\OneDrive\\Рабочий стол\\tmp","typeFiles":"","sizeFiles":"","wordLeft":"","wordRight":"","changed":"","remember":["esp"],"regexp":["[А-Яа-яЁё]{4}[-.]\\d{6}[-.]\\d{3}"]}},{"9kjs8jhks2ccb4l52sqx":{"name":"Сети","pathFrom":"C:\\Users\\ashot\\OneDrive\\Рабочий стол\\КУРСОВЫЕ РАБОТЫ\\2_КУРС\\Сети","pathTo":"C:\\Users\\ashot\\OneDrive\\Рабочий стол\\tmp","typeFiles":"","sizeFiles":"","wordLeft":"","wordRight":"","changed":"","remember":[],"regexp":[]}}]
2 changes: 1 addition & 1 deletion src/dev/index.dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@

</main>

<script crossorigin src="./api.dev.js"></script>
<script type="module" crossorigin src="./api.dev.js"></script>


</body>
Expand Down
164 changes: 48 additions & 116 deletions src/dev/module/OtherMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,43 @@ module.exports = function () {

let globalActive = false

const updateFilesList = elems => {
let tmp = []

elems.forEach(el => {
$._fs.cleanActiveList()

if (!el.checked) {
tmp.push(el.dataset.path)
}
})

$.files_ = $._fs.getFiles().filter(el => {
if (tmp.includes(el.path)) {
return false
}
return true
}).map(el => el)

let keySize = Object.keys($.files_).length

if (keySize === $._fs.getCountFiles()) {
document.querySelector('.check__all').setAttribute('checked', 'true')
document.querySelector('.check__all').checked = true
} else {
document.querySelector('.check__all').removeAttribute('checked')
document.querySelector('.check__all').checked = false
}

if (keySize > 0) {
document.querySelector('.search__result').innerHTML = `Выбрано ${keySize} файлов`
document.querySelector('.global__button-tran').style.display = 'flex'
} else {
document.querySelector('.search__result').innerHTML = `Найдено ${$._fs.getCountFiles()} файлов`
document.querySelector('.global__button-tran').style.display = 'none'
}
}

document.querySelector('.sort__up').addEventListener('click', function () {
document.querySelector('.file__context').scrollTop = 0
})
Expand Down Expand Up @@ -95,34 +132,6 @@ module.exports = function () {
}
})

document.querySelector('.setting-button').addEventListener('click', function () {
let $this = document.documentElement.getAttribute('theme')

if ($this === 'dark') {
$._fs.setTheme('light')
$.config.theme = 'light'
} else {
$._fs.setTheme('dark')
$.config.theme = 'dark'
}

fs.writeFileSync(path.join(__dirname, rpath.config), JSON.stringify($.config))
})

document.querySelector('.lang-button').addEventListener('click', function () {
let $this = document.documentElement.getAttribute('lang')

if ($this === 'ru') {
$._fs.setLang('en')
$.config.lang = 'en'
} else {
$._fs.setLang('ru')
$.config.lang = 'ru'
}

fs.writeFileSync(path.join(__dirname, rpath.config), JSON.stringify($.config))
})

document.querySelector('.regexp__list').addEventListener('click', function () {
const target = this.querySelectorAll('button')
if (!target) return false
Expand Down Expand Up @@ -401,58 +410,6 @@ module.exports = function () {
}
})

document.querySelector('.preset__list').addEventListener('click', function (event) {
const targetPreset = this.querySelectorAll('input')
if (!targetPreset) return false;

[].forEach.call(targetPreset, el => {
el.onclick = () => {
$.tmpf['id'] = el.dataset.id
$.tmpf['from'] = el.dataset.from
$.tmpf['to'] = el.dataset.to
$.tmpf['remember'] = el.dataset.remember
$.tmpf['regexp'] = el.dataset.regexp

$.config.ActivePreset = el.dataset.id

$._fs.setPreset($.tmpf['id'], $.tmpf['from'], $.tmpf['to'], $.tmpf['remember'], $.tmpf['regexp'])
fs.writeFileSync(path.join(__dirname, rpath.config), JSON.stringify($.config))

document.querySelector('.tb__popup').style.display = 'none'
}
})

const targetTrashPreset = this.querySelectorAll('.trash__preset');

[].forEach.call(targetTrashPreset, el => {
el.onclick = () => {
let preset = el.dataset.id
let active = $._fs.getPreset()

let tmpdb = []

if (preset === active) {
$._fs.createNotice('Данный пресет активен')
} else {
for (let x in $.db) {
let tmp = String(Object.keys($.db[x]))
if (tmp !== preset) {
tmpdb.push($.db[x])
}
}

$.db.length = 0

$.db.push(...tmpdb)

$._fs.updateDB($.db)
$._fs.updatePreset()
fs.writeFileSync(path.join(__dirname, rpath.db), JSON.stringify($.db))
}
}
})
})

document.querySelector('.file__thead input').addEventListener('click', function (event) {
$.files_ = []

Expand Down Expand Up @@ -503,6 +460,16 @@ module.exports = function () {
document.querySelector('.file__context').addEventListener('contextmenu', function (e) {
try {
let t = e.srcElement.offsetParent.parentNode.querySelector('.context__file .create__props')
let u = e.srcElement.offsetParent.parentNode.querySelector('.context__file .delete__props')

u.addEventListener('click', async () => {
let i = e.srcElement.offsetParent.parentNode.querySelector('.file__table-ctx input')
let elems = e.srcElement.offsetParent.parentNode.parentNode.parentNode.parentNode.querySelectorAll('input')

await $._fs.trashFilesSync(i.dataset.path, i.dataset.id)

updateFilesList(elems)
})

t.addEventListener('click', function () {
let i = e.srcElement.offsetParent.parentNode.querySelector('.file__table-ctx input')
Expand Down Expand Up @@ -630,42 +597,7 @@ module.exports = function () {
} else {
let elems = e.srcElement.offsetParent.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.querySelectorAll('input')

let tmp = []

elems.forEach(el => {
$._fs.cleanActiveList()

if (!el.checked) {
tmp.push(el.dataset.path)
}
})

$.files_ = $._fs.getFiles().filter(el => {
if (tmp.includes(el.path)) {
return false
}
return true
}).map(el => el)

let keySize = Object.keys($.files_).length

console.log(keySize + ' ' + $._fs.getCountFiles())

if (keySize === $._fs.getCountFiles()) {
document.querySelector('.check__all').setAttribute('checked', 'true')
document.querySelector('.check__all').checked = true
} else {
document.querySelector('.check__all').removeAttribute('checked')
document.querySelector('.check__all').checked = false
}

if (keySize > 0) {
document.querySelector('.search__result').innerHTML = `Выбрано ${keySize} файлов`
document.querySelector('.global__button-tran').style.display = 'flex'
} else {
document.querySelector('.search__result').innerHTML = `Найдено ${$._fs.getCountFiles()} файлов`
document.querySelector('.global__button-tran').style.display = 'none'
}
updateFilesList(elems)
}
} catch (e) {

Expand Down
82 changes: 82 additions & 0 deletions src/dev/module/SpecialOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,86 @@ module.exports = function () {

$._fs.sortFiles(Number(column.value), Number(type.value))
})

document.querySelector('.setting-button').addEventListener('click', function () {
let $this = document.documentElement.getAttribute('theme')

if ($this === 'dark') {
$._fs.setTheme('light')
$.config.theme = 'light'
} else {
$._fs.setTheme('dark')
$.config.theme = 'dark'
}

fs.writeFileSync(path.join(__dirname, rpath.config), JSON.stringify($.config))
})

document.querySelector('.lang-button').addEventListener('click', function () {
let $this = document.documentElement.getAttribute('lang')

if ($this === 'ru') {
$._fs.setLang('en')
$.config.lang = 'en'
} else {
$._fs.setLang('ru')
$.config.lang = 'ru'
}

fs.writeFileSync(path.join(__dirname, rpath.config), JSON.stringify($.config))
})

document.querySelector('.preset__list').addEventListener('click', function (event) {
const targetPreset = this.querySelectorAll('input')
if (!targetPreset) return false;

[].forEach.call(targetPreset, el => {
el.onclick = () => {
$.tmpf['id'] = el.dataset.id
$.tmpf['from'] = el.dataset.from
$.tmpf['to'] = el.dataset.to
$.tmpf['remember'] = el.dataset.remember
$.tmpf['regexp'] = el.dataset.regexp

$.config.ActivePreset = el.dataset.id

$._fs.setPreset($.tmpf['id'], $.tmpf['from'], $.tmpf['to'], $.tmpf['remember'], $.tmpf['regexp'])
fs.writeFileSync(path.join(__dirname, rpath.config), JSON.stringify($.config))

document.querySelector('.tb__popup').style.display = 'none'
document.querySelector('.check__all').removeAttribute('checked')
document.querySelector('.check__all').checked = false
}
})

const targetTrashPreset = this.querySelectorAll('.trash__preset');

[].forEach.call(targetTrashPreset, el => {
el.onclick = () => {
let preset = el.dataset.id
let active = $._fs.getPreset()

let tmpdb = []

if (preset === active) {
$._fs.createNotice('Данный пресет активен')
} else {
for (let x in $.db) {
let tmp = String(Object.keys($.db[x]))
if (tmp !== preset) {
tmpdb.push($.db[x])
}
}

$.db.length = 0

$.db.push(...tmpdb)

$._fs.updateDB($.db)
$._fs.updatePreset()
fs.writeFileSync(path.join(__dirname, rpath.db), JSON.stringify($.db))
}
}
})
})
}
Loading

0 comments on commit d7bbb96

Please sign in to comment.