deffiine path

This commit is contained in:
dev sp
2024-02-07 16:23:55 +00:00
parent 7593e3b823
commit f2fe34c82c
7 changed files with 184 additions and 30 deletions

View File

@@ -0,0 +1,57 @@
---
import Layout from "../layouts/Layout.astro";
---
<Layout title="Upload File | Barta-India">
<main>
<div class="container mx-auto px-4 flex flex-col space-y-4">
<h1>Upload File</h1>
<form action="https://apisp.dev2.cicdhosting.com/news/add-file/" method="post" enctype="multipart/form-data">
<label for="file">Choose a file:</label>
<input type="file" name="file" id="file" required>
<br>
<input type="submit" value="Upload">
</form>
</div>
</main>
</Layout>
<script is:inline>
// function uploadFile() {
// var fileInput = document.getElementById('fileInput');
// var file = fileInput.files[0];
// if (file) {
// var formData = new FormData();
// formData.append('fileInput', file);
// fetch('https://apisp.dev2.cicdhosting.com/news/add-file/?action=save', {
// method: 'POST',
// body: formData
// })
// .then(response => response.json())
// .then(data => {
// document.getElementById('status').innerText = data.message;
// })
// .catch(error => {
// console.error('Error:', error);
// });
// } else {
// document.getElementById('status').innerText = 'Please select a file.';
// }
// }
// function fileUpload(){
// let formData = new FormData(document.getElementById('uploadForm'));
// fetch(`https://apisp.dev2.cicdhosting.com/news/add-file/?action=save`, {
// method: 'POST',
// body: formData
// })
// .then(response => response.json())
// .then(data => {
// console.log(data);
// })
// .catch(error => {
// console.log('An error occurred', error);
// });
// }
</script>

View File

@@ -0,0 +1,267 @@
---
import Layout from "../layouts/Layout.astro";
import ImageUpload from "../components/ImageUpload.vue";
---
<Layout title="Add News | Barta India">
<main>
<div>
<section class="container mx-auto px-4 md:max-w-3xl mt-40 space-y-4 shadow-xl rounded-xl p-4">
<h1 class="text-center text-2xl underline decoration-4 decoration-[#580a0a]">Genarate New News</h1>
<form id="newsPara" class="flex flex-col space-y-4" enctype="multipart/form-data">
<label for="language">Language<span class="text-[#580a0a] font-bold">*</span></label>
<select required onchange="qryWithLang();" name="language" id="language" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl p-2">
<option value="0">-Select-</option>
<option value="english">English</option>
<option value="bengali">Bengali</option>
</select>
<div class="flex flex-col">
<label for="category">Category<span class="text-[#580a0a] font-bold">*</span></label>
<select name="category" id="category" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl p-2">
<option value="0">-Select-</option>
<option value="national">National</option>
<option value="politics">Politics</option>
<option value="local">Local</option>
<option value="technology">Technology</option>
<option value="world">World</option>
</select>
</div>
<div class="flex flex-col ">
<label for="preText">News Paragraph</label>
<textarea onchange="buttonVisibility();" required name="preText" id="preText" cols="30" maxlength="1000000" rows="10" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl"></textarea>
</div>
<div class="flex flex-col">
<textarea required name="systemMessage" id="systemMessage" cols="30" rows="3" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl"></textarea>
</div>
<div>
<button id="genButton" style="display: none;" onclick="submitNewsPara(event);" class="bg-[#580a0a] text-white px-4 py-2 rounded-lg" >Genarate</button>
<button id="genButton2" style="display: block;" class="bg-[#580a0a] text-white px-4 py-2 rounded-lg opacity-50 cursor-not-allowed" >Genarate</button>
</div>
<!-- <input id="message" type="text" value="" class="border-2 border-[#580a0a] p-2 focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl"/> -->
</form>
</section>
<section id="formSection" style="display: none;" class="container mx-auto md:max-w-3xl px-4 shadow-xl rounded-xl p-6">
<div class="flex justify-center">
<h1 class="text-xl my-6 p-2 border-2 bg-[#580a0a] text-white rounded-full">Add News to Barta-India's Page</h1>
</div>
<p>All(<span class="text-[#580a0a] font-bold">*</span>) are mandatory fields</p>
<form id="newsForm" class="flex flex-col space-y-4">
<div class="flex flex-col">
<label for="status">Status<span class="text-[#580a0a] font-bold">*</span></label>
<select name="status" id="status" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl p-2" required>
<option value="null">-Select-</option>
<option value="published">Published</option>
<option value="draft">Draft</option>
<option value="archived">Archived</option>
</select>
</div>
<div class="flex flex-col">
<label for="language">Language<span class="text-[#580a0a] font-bold">*</span></label>
<select name="language" id="language" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl p-2" required>
<option value="null">-Select-</option>
<option value="bengali">Bengali</option>
<option value="english">English</option>
</select>
</div>
<div class="flex flex-col">
<label for="category">Category<span class="text-[#580a0a] font-bold">*</span></label>
<select name="category" id="category" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl p-2">
<option value="null">-Select-</option>
<option value="national">National</option>
<option value="politics">Politics</option>
<option value="local">Local</option>
<option value="technology">Technology</option>
<option value="world">World</option>
</select>
</div>
<div class="flex flex-col">
<label for="title">Title<span class="text-[#580a0a] font-bold">*</span></label>
<input name="title" id="title" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl p-2" type="text" required>
</div>
<div class="flex flex-col">
<label for="slug">Slug<span class="text-[#580a0a] font-bold">*</span></label>
<input oninput="updateSlug();" name="slug" id="slug" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl p-2" type="text" required>
</div>
<div class="flex flex-col">
<label for="heading">Heading<span class="text-[#580a0a] font-bold">*</span></label>
<input name="heading" id="heading" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl p-2" type="text" required>
</div>
<div class="flex flex-col">
<label for="meta_title">Meta Title<span class="text-[#580a0a] font-bold">*</span></label>
<input name="meta_title" id="meta_title" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl p-2" type="text" placeholder="max: length 60 characters & try to use common words" required>
</div>
<div class="flex flex-col">
<label for="meta_description">Meta Description<span class="text-[#580a0a] font-bold">*</span></label>
<input name="meta_description" id="meta_description" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl p-2" type="text" placeholder="max: length 160 characters & try to use common words" required>
</div>
<div class="flex flex-col">
<label for="in_brief">In Brief<span class="text-[#580a0a] font-bold">*</span></label>
<input name="in_brief" id="in_brief" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl p-2" type="text" placeholder="max: length 280 characters & try to descibe" required>
</div>
<div class="flex flex-col">
<label class="text-lg" for="content">News Description<span class="text-[#580a0a] font-bold">*</span></label>
<textarea class="border-2 p-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl" name="content" id="content" cols="30" rows="10" required></textarea>
</div>
<div class="flex flex-col">
<label for="upldFile">Upload File</label>
<input id="upldFile" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl" type="file">
</div>
<div class="flex float-right">
<button onclick="callApi(event);" class="bg-[#580a0a] text-white px-4 py-2 rounded-lg">Save</button>
</div>
</form>
</section>
<section class="bg-white rounded-full px-6 py-4" id="loadingSection" style="display: none;">
<div class="flex flex-col justify-center place-items-center">
<div class="load-aimate animate-spin "></div>
<p>Processing...</p>
</div>
</section>
<!-- <section class="container mx-auto">
<div>
<dialog id="d" class="w-[50%]">
<form method="dialog">
<p>Modal Content Modal Content Lorem ipsum dolor sit, amet consectetur adipisicing elit. Hic consequatur aspernatur, explicabo sequi perspiciatis quisquam voluptates tenetur placeat numquam consectetur! Tempore expedita facilis tempora labore at illo beatae eligendi magnam.</p>
<button>ok</button>
</form>
</dialog>
<button onclick="d.showModal()">Open</button>
</div>
</section> -->
</div>
</main>
</Layout>
<script is:inline>
function qryWithLang(){
let langValue = document.getElementById('language').value;
document.getElementById('systemMessage').value = `need title, heading not more than 160 characters, meta_title not more than 60 characters, meta_description not more than 160 characters, short_description not more than 280 characters, long_description below 2000 characters, all are ${langValue} language all in a json structure`;
// give me long description below 2000 characters, title, heading not more than 160 characters, short desciption not more than 280 characters, meta_title not more than 60 characters and try to use common words, meta_description not more than 160 characters and try to use common words, all text are convert to ${langValue} language, give me all in a json structure`
// provide meta_title within 60 characters, meta_description within 160 characters, short_description within 280 characters in English, bengali and hindi all in a json structure
// provide meta_title within 60 characters, meta_description within 160 characters, short_description within 280 characters in English, bengali and hindi all in a json structure
}
function buttonVisibility() {
var preTextValue = document.getElementById('preText').value.trim();
var systemMessageValue = document.getElementById('systemMessage').value.trim();
var languageValue = document.getElementById('language').value;
var categoryValue = document.getElementById('category').value;
var genButton = document.getElementById('genButton');
var genButton2 = document.getElementById('genButton2');
if (preTextValue.length > 0 && systemMessageValue.length > 0 && languageValue !== null) {
genButton.style.display = 'block';
genButton2.style.display = 'none';
} else {
genButton.style.display = 'none';
genButton2.style.display = 'block';
}
}
function submitNewsPara(event) {
event.preventDefault();
let genButton = document.getElementById('genButton');
let langInput = document.getElementById('language');
let loadSection = document.getElementById('loadingSection');
let newsData = document.getElementById('newsPara');
loadSection.style.display = 'block';
genButton.disabled = true;
langInput.disabled = true;
genButton.style.cursor = 'not-allowed';
let formData = new FormData(newsData);
fetch(`https://apisp.dev2.cicdhosting.com/_dedicated/dwd/`, {
method: 'POST',
body: formData,
})
.then(data => data.json())
.then(data => {
// if (data === 200) {
// counter++;
// } else {
// formSection genButton brightness-50
console.log(data)
// }
let newsData = data.choices[0].message.content;
if(newsData){
document.getElementById('formSection').style.display = 'block';
loadSection.style.display = 'none';
genButton.disabled = false;
genButton.style.cursor = 'pointer';
langInput.disabled = false;
// document.getElementById('loadingSection').classList.remove = 'brightness-50';
// document.getElementById('genButton').classList.remove = 'disabled';
}
let jsonObject = JSON.parse(newsData);
document.getElementById('title').value = jsonObject.title;
document.getElementById('slug').value = jsonObject.title;
document.getElementById('heading').value = jsonObject.heading;
document.getElementById('meta_title').value = jsonObject.meta_title;
document.getElementById('meta_description').value = jsonObject.meta_description;
document.getElementById('in_brief').value = jsonObject.short_description;
document.getElementById('content').value = jsonObject.long_description;
if(jsonObject.long_description){
// document.getElementById('content').value = jsonObject.long_description;
}
})
.catch(error => {
console.error('Error occurred', error);
});
}
function slugify(text) {
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w-]+/g, '') // Remove all non-word characters
.replace(/--+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
function updateSlug() {
const titleInput = document.getElementById('slug');
const slugInput = document.getElementById('slug');
const titleValue = titleInput.value;
slugInput.value = slugify(titleValue);
}
function callApi(event) {
event.preventDefault();
let slugValue = document.getElementById('slug').value;
let newsData = document.getElementById('newsForm');
let formData = new FormData(newsData);
fetch(`https://apisp.dev2.cicdhosting.com/news/add-news/?action=save`, {
method: 'POST',
body: formData,
})
.then(data => data.json())
.then(data => {
if (data.success === true) {
window.location.href= `/add-file?slug=${slugValue}`
// console.log(slugValue)
console.log('Form Data Submitted Successfully');
} else {
console.log('Data Submit Failed');
}
console.log(data);
})
.catch(error => {
console.error('Error occurred', error);
});
}
</script>
<style>
#loadingSection{
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.load-aimate{
width: 60px;
height: 60px;
border-radius: 50%;
border-left: 5px solid #580a0a;
border-right: 5px solid #580a0a;
border-bottom: 5px solid #580a0a;
border-top: 5px solid #FFFFFF;
background-color: #FFFFFF;
}
</style>

View File

@@ -0,0 +1,58 @@
---
import Layout from "../../layouts/Layout.astro";
---
<Layout title="Edit News | Barta-India">
<main>
<div>
<section class="container mx-auto px-4">
<div class="flex flex-col">
<p class="text-2xl">Edit News</p>
<select name="lang" id="lang">Select Language
<option value="en">English</option>
<option value="bn">Bengali</option>
<option value="hi">Hindi</option>
<option value="zh">Mandarine</option>
<option value="se">Spanish</option>
</select>
<table class="border-2">
<thead>
<tr class="text-center">
<th>ID</th>
<th>Status</th>
<th>Edit</th>
</tr>
</thead>
<tbody class="text-center border-2" id="statusTableBody"></tbody>
</table>
</div>
</section>
</div>
</main>
</Layout>
<script is:inline>
fetch(`https://apisp.dev2.cicdhosting.com/_dedicated/dwd/edit-news-list/`)
.then(response => response.json())
.then(data => {
console.log(data);
let tableBody = document.getElementById('statusTableBody');
data.forEach(function(singleData) {
let row = tableBody.insertRow();
let cellId = row.insertCell(0);
cellId.innerHTML = singleData.id;
let cellStatus = row.insertCell(1);
cellStatus.innerHTML = singleData.status;
let cellEdit = row.insertCell(2);
let editButton = document.createElement('a');
editButton.innerText = 'Edit';
editButton.href = `/editor/?edit=${singleData.slug}&lang=${document.getElementById('lang').value}`
editButton.addEventListener('click', function() {
// Add your edit functionality here
// console.log('Editing ID:', singleData.id);
});
cellEdit.appendChild(editButton);
});
})
.catch(error => console.error('Error fetching data:', error));
</script>

View File

@@ -0,0 +1,77 @@
---
import Layout from "../layouts/Layout.astro";
---
<Layout title="">
<main>
<div>
<section class="container mx-auto px-4 md:max-w-3xl mt-40 space-y-4 shadow-xl rounded-xl p-4">
<h1 class="text-center text-2xl underline decoration-4 decoration-[#580a0a]">Genarate New News</h1>
<form id="newsPara" class="flex flex-col space-y-4" enctype="multipart/form-data">
<label for="language">Language<span class="text-[#580a0a] font-bold">*</span></label>
<select name="language" id="language" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl p-2">
<option value="null">-Select-</option>
<option value="English">English</option>
<option value="Bengali">Bengali</option>
</select>
<div class="flex flex-col">
<label for="category">Category<span class="text-[#580a0a] font-bold">*</span></label>
<select name="category" id="category" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl p-2">
<option value="null">-Select-</option>
<option value="national">National</option>
<option value="politics">Politics</option>
<option value="local">Local</option>
<option value="technology">Technology</option>
<option value="world">World</option>
</select>
</div>
<div class="flex flex-col ">
<label for="content">Nes Paragraph</label>
<textarea name="content" id="content" cols="30" maxlength="1000000" rows="10" class="border-2 border-[#580a0a] focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl"></textarea>
</div>
<div>
<button onclick="submitNewsPara(event);" class="bg-[#580a0a] text-white px-4 py-2 rounded-lg" >Genarate</button>
<h1 id="message"></h1>
</div>
<!-- <input id="message" type="text" value="" class="border-2 border-[#580a0a] p-2 focus:outline-none focus:border-4 focus:border-[#580a0a] rounded-xl"/> -->
</form>
</section>
</div>
</main>
</Layout>
<script is:inline>
function submitNewsPara(event) {
event.preventDefault();
let newsData = document.getElementById('newsPara');
let formData = new FormData(newsData);
// formData.append('content', document.getElementById('content').value);
// console.log('FormData entries:');
// for (const entry of formData.entries()) {
// console.log(typeof entry[0], entry[0]);
// }
fetch(`https://apisp.dev2.cicdhosting.com/_dedicated/dwd/`, {
method: 'POST',
body: formData,
})
.then(data => data.json())
.then(data => {
// if (data === 200) {
// counter++;
// } else {
console.log(data)
// }
let newsData = data.choices[0].message.content;
const jsonObject = JSON.parse(newsData);
document.getElementById('message').innerHTML = jsonObject.title + "<br> Description: " + jsonObject.description; //jsonObject;
// document.getElementById('message').value = jsonObject.title;
// console.log(newsData);
// return data.choices[0].message.content;
})
.catch(error => {
console.error('Error occurred', error);
});
}
</script>

View File

@@ -0,0 +1,21 @@
---
import Layout from "../../layouts/Layout.astro";
import EditNews from "../../components/EditNews.vue";
---
<Layout title="Edit News | Barta-India">
<main>
<div>
<EditNews client:visible />
</div>
</main>
<!-- </Layout>
<script is:inline>
let pramsURL = document.location.href.split('/')[3].split('edit=')[1];
document.getElementById('url').innerHTML = pramsURL;
// console.log(pramsURL)
function getNewsData(){
}
</script> -->