1662485400
We are hiring at all levels (including FTE researchers and interns)! If you are interested in working with us on NLP and large-scale pre-trained models, please send your resume to fuwei@microsoft.com.
Transformers at Scale = DeepNet + X-MoE
Stability - DeepNet: scaling Transformers to 1,000 Layers and beyond
Efficiency & Transferability - X-MoE: scalable & finetunable sparse Mixture-of-Experts (MoE)
MetaLM: Language Models are General-Purpose Interfaces
The Big Convergence - Large-scale self-supervised pre-training across tasks
(predictive and generative), languages
(100+ languages), and modalities
(language, image, audio, layout/format + language, vision + language, audio + language, etc.)
UniLM: unified pre-training for language understanding and generation
InfoXLM/XLM-E: multilingual/cross-lingual pre-trained models for 100+ languages
DeltaLM/mT6: encoder-decoder pre-training for language generation and translation for 100+ languages
MiniLM: small and fast pre-trained models for language understanding and generation
AdaLM: domain, language, and task adaptation of pre-trained models
EdgeLM(
NEW
): small pre-trained models on edge/client devices
SimLM (
NEW
): similarity matching with language model pre-training
BEiT(-2): generative self-supervised pre-training for vision / BERT Pre-Training of Image Transformers
DiT (
NEW
): self-supervised pre-training for Document Image Transformers
WavLM: speech pre-training for full stack tasks
LayoutLM/LayoutLMv2/LayoutLMv3: multimodal (text + layout/format + image) pre-training for Document AI (e.g. scanned documents, PDF, etc.)
LayoutXLM: multimodal (text + layout/format + image) pre-training for multilingual document understanding
MarkupLM: markup language model pre-training for visually-rich document understanding
UniSpeech: unified pre-training for self-supervised learning and supervised learning for ASR
UniSpeech-SAT: universal speech representation learning with speaker-aware pre-training
SpeechT5: encoder-decoder pre-training for spoken language processing
VLMo: Unified vision-language pre-training
VL-BEiT (
NEW
): Generative Vision-Language Pre-training - evolution of BEiT to multimodal
BEiT-3 (
NEW
): a general-purpose multimodal foundation model, and a major milestone of The Big Convergence of Large-scale Pre-training Across Tasks, Languages, and Modalities.
s2s-ft: sequence-to-sequence fine-tuning toolkit
Aggressive Decoding (
NEW
): lossless and efficient sequence-to-sequence decoding algorithm
TrOCR: transformer-based OCR w/ pre-trained models
LayoutReader: pre-training of text and layout for reading order detection
XLM-T: multilingual NMT w/ pretrained cross-lingual encoders
***** New May, 2022
: Aggressive Decoding release *****
***** New April, 2022
: LayoutLMv3 release *****
ACM MM 2022
"***** March, 2022
: EdgeFormer release *****
***** March, 2022
: DiT release *****
ACM MM 2022
"***** October, 2021
: WavLM release *****
***** October, 2021
: MarkupLM release *****
ACL 2022
"***** September, 2021
: TrOCR release *****
***** August, 2021
: LayoutReader release *****
EMNLP 2021
"***** August, 2021
: DeltaLM release *****
***** July, 2021
: BEiT release *****
***** June, 2021
: LayoutXLM | AdaLM | MiniLMv2 release *****
ACL 2021
"ACL 2021
"***** May, 2021
: LayoutLMv2 | LayoutXLM release *****
ACL 2021
"***** February, 2020
: UniLM v2 | MiniLM v1 | LayoutLM v1 | s2s-ft v1 release *****
KDD 2020
"NeurIPS 2020
"ICML 2020
"***** October 1st, 2019: UniLM v1 release *****
NeurIPS 2019
paper entitled "Unified Language Model Pre-training for Natural Language Understanding and Generation". UniLM (v1) achieves the new SOTA results in NLG (especially sequence-to-sequence generation) tasks, including abstractive summarization (the Gigaword and CNN/DM datasets), question generation (the SQuAD QG dataset), etc.Author: microsoft
Source code: https://github.com/microsoft/unilm
License: MIT license
#python #ArtificialIntelligence #ai #machinelearning
1662485400
We are hiring at all levels (including FTE researchers and interns)! If you are interested in working with us on NLP and large-scale pre-trained models, please send your resume to fuwei@microsoft.com.
Transformers at Scale = DeepNet + X-MoE
Stability - DeepNet: scaling Transformers to 1,000 Layers and beyond
Efficiency & Transferability - X-MoE: scalable & finetunable sparse Mixture-of-Experts (MoE)
MetaLM: Language Models are General-Purpose Interfaces
The Big Convergence - Large-scale self-supervised pre-training across tasks
(predictive and generative), languages
(100+ languages), and modalities
(language, image, audio, layout/format + language, vision + language, audio + language, etc.)
UniLM: unified pre-training for language understanding and generation
InfoXLM/XLM-E: multilingual/cross-lingual pre-trained models for 100+ languages
DeltaLM/mT6: encoder-decoder pre-training for language generation and translation for 100+ languages
MiniLM: small and fast pre-trained models for language understanding and generation
AdaLM: domain, language, and task adaptation of pre-trained models
EdgeLM(
NEW
): small pre-trained models on edge/client devices
SimLM (
NEW
): similarity matching with language model pre-training
BEiT(-2): generative self-supervised pre-training for vision / BERT Pre-Training of Image Transformers
DiT (
NEW
): self-supervised pre-training for Document Image Transformers
WavLM: speech pre-training for full stack tasks
LayoutLM/LayoutLMv2/LayoutLMv3: multimodal (text + layout/format + image) pre-training for Document AI (e.g. scanned documents, PDF, etc.)
LayoutXLM: multimodal (text + layout/format + image) pre-training for multilingual document understanding
MarkupLM: markup language model pre-training for visually-rich document understanding
UniSpeech: unified pre-training for self-supervised learning and supervised learning for ASR
UniSpeech-SAT: universal speech representation learning with speaker-aware pre-training
SpeechT5: encoder-decoder pre-training for spoken language processing
VLMo: Unified vision-language pre-training
VL-BEiT (
NEW
): Generative Vision-Language Pre-training - evolution of BEiT to multimodal
BEiT-3 (
NEW
): a general-purpose multimodal foundation model, and a major milestone of The Big Convergence of Large-scale Pre-training Across Tasks, Languages, and Modalities.
s2s-ft: sequence-to-sequence fine-tuning toolkit
Aggressive Decoding (
NEW
): lossless and efficient sequence-to-sequence decoding algorithm
TrOCR: transformer-based OCR w/ pre-trained models
LayoutReader: pre-training of text and layout for reading order detection
XLM-T: multilingual NMT w/ pretrained cross-lingual encoders
***** New May, 2022
: Aggressive Decoding release *****
***** New April, 2022
: LayoutLMv3 release *****
ACM MM 2022
"***** March, 2022
: EdgeFormer release *****
***** March, 2022
: DiT release *****
ACM MM 2022
"***** October, 2021
: WavLM release *****
***** October, 2021
: MarkupLM release *****
ACL 2022
"***** September, 2021
: TrOCR release *****
***** August, 2021
: LayoutReader release *****
EMNLP 2021
"***** August, 2021
: DeltaLM release *****
***** July, 2021
: BEiT release *****
***** June, 2021
: LayoutXLM | AdaLM | MiniLMv2 release *****
ACL 2021
"ACL 2021
"***** May, 2021
: LayoutLMv2 | LayoutXLM release *****
ACL 2021
"***** February, 2020
: UniLM v2 | MiniLM v1 | LayoutLM v1 | s2s-ft v1 release *****
KDD 2020
"NeurIPS 2020
"ICML 2020
"***** October 1st, 2019: UniLM v1 release *****
NeurIPS 2019
paper entitled "Unified Language Model Pre-training for Natural Language Understanding and Generation". UniLM (v1) achieves the new SOTA results in NLG (especially sequence-to-sequence generation) tasks, including abstractive summarization (the Gigaword and CNN/DM datasets), question generation (the SQuAD QG dataset), etc.Author: microsoft
Source code: https://github.com/microsoft/unilm
License: MIT license
#python #ArtificialIntelligence #ai #machinelearning
1650391200
The Ansible Jupyter Kernel adds a kernel backend for Jupyter to interface directly with Ansible and construct plays and tasks and execute them on the fly.
ansible-kernel
is available to be installed from pypi but you can also install it locally. The setup package itself will register the kernel with Jupyter
automatically.
pip install ansible-kernel
python -m ansible_kernel.install
pip install -e .
python -m ansible_kernel.install
pip install ansible-kernel
python -m ansible_kernel.install --sys-prefix
jupyter notebook
# In the notebook interface, select Ansible from the 'New' menu
docker run -p 8888:8888 benthomasson/ansible-jupyter-kernel
Then copy the URL from the output into your browser:
http://localhost:8888/?token=ABCD1234
Normally Ansible
brings together various components in different files and locations to launch a playbook and performs automation tasks. For this jupyter
interface you need to provide this information in cells by denoting what the cell contains and then finally writing your tasks that will make use of them. There are Examples available to help you, in this section we'll go over the currently supported cell types.
In order to denote what the cell contains you should prefix it with a pound/hash symbol (#) and the type as listed here as the first line as shown in the examples below.
The inventory that your tasks will use
#inventory
[all]
ahost ansible_connection=local
anotherhost examplevar=val
This represents the opening block of a typical Ansible
play
#play
name: Hello World
hosts: all
gather_facts: false
This is the default cell type if no type is given for the first line
#task
debug:
#task
shell: cat /tmp/afile
register: output
This takes an argument that represents the hostname. Variables defined in this file will be available in the tasks for that host.
#host_vars Host1
hostname: host1
This takes an argument that represents the group name. Variables defined in this file will be available in the tasks for hosts in that group.
#group_vars BranchOfficeX
gateway: 192.168.1.254
This takes an argument that represents the filename for use in later cells
#vars example_vars
message: hello vars
#play
name: hello world
hosts: localhost
gather_facts: false
vars_files:
- example_vars
This takes an argument in order to create a templated file that can be used in later cells
#template hello.j2
{{ message }}
#task
template:
src: hello.j2
dest: /tmp/hello
Provides overrides typically found in ansible.cfg
#ansible.cfg
[defaults]
host_key_checking=False
You can find various example notebooks in the repository
It's possible to use whatever python development process you feel comfortable with. The repository itself includes mechanisms for using pipenv
pipenv install
...
pipenv shell
Author: ansible
Source Code: https://github.com/ansible/ansible-jupyter-kernel
License: Apache-2.0 License
1604946745
Yoga gives peace to the body and mind that helps in living a healthy & happy life. It comes with a lot of benefits for both mental and physical health. Meditation and Yoga can cure many diseases and after seeing the results across the world, people are getting more into meditation and yoga. Many of them are trying to motivate others for shifting towards yoga by saving a little bit of time from daily routine. It’s not a bad idea to start a carrier in yoga as a yoga trainer, teacher, consultant or Therapist. If you are interested in it and doing it for a longer period.
Divyaa yoga institute launched 200 yoga teacher training certification courses in Ghaziabad and come up as a world-class professional yoga institute in Delhi NCR for the people who love yoga and ready to make a carrier in it. This is the best yoga teacher training institute in India that provides group yoga classes, yoga certification courses, yoga workshops, and provides many other courses that can help in gaining professional knowledge.
200 hour yoga teacher training course in India facilitates a professional syllabus that starts from basic and goes to the advanced level. They provide personal female/ male yoga trainer to the students according to their requirements.
200 hour yoga teacher training course syllabus includes mantra chanting. It releases positive energy from your mind that helps in decreasing negative thoughts. The study of asana is one of the most important points in the syllabus. Their trainers take care of the proper posture and body alignment so that the risk of injury can be reduced.
When teachers teach, they want to be sure that every student is getting things properly. We provide personal yoga trainer on demand to balance the comfortability while doing yoga practice. When you will invest in yoga, it will make your life smoother and happier forever. Taking yoga as your carrier is an excellent option because in this journey you will give knowledge of being healthy, happy, and calm to others. You will feel great when you will be the reason for the happiness of thousands of people who come to you in search of stability and calmness in their life.
For beginners, it is very important to do pose carefully to avoid injury. Their trainers use props at early stages so that beginners can improve after a few days. Improvisation plays a crucial role and at Divyaa yoga institute, professional teachers take care of every little thing so that every single person gets satisfaction in terms of peace, happiness, and whatever their goal is after adding meditation and yoga to their life schedule.
On the launch of 200 hour yoga teacher training course, the owner of Divyaa yoga institute said that “Yoga is an ancient practice and meditation that is now on everyone’s tongue. People are getting familiar with yoga because of positive results all across the world. Yoga is come up as a treatment for heart and other health issues. We are trying to encourage people, to give your mind and body relaxation from the stress and tension that they have filled up in their life because of pressure and duties.”
He further adds about the course “We are offering 200 hour yoga teacher training course for the people who have an interest or have some experience in the yoga profession. Now, you can convert your interest into a profession by opting for our professional yoga courses in India. We have experienced professional yoga trainers at our institute from across the world and sharing their experience with the people who are willing or trying to join yoga for the rest of their life.”
About Divyaa yoga institute
Divyaa yoga institute is a leading international yoga school in Ghaziabad, that provides several yoga programs that include yoga workshops, group yoga classes, corporate yoga classes, private yoga classes, and stress management & spiritual classes in Ghaziabad.
If you are interested in yoga whether you have experience or not and want to take yoga as your profession then Divyaa yoga institute is the right place for your goal. They will give shape to your interest and develop your yoga skills in order to make you a professional yoga trainer. They offer courses like yoga for better living certification courses of 21 days, meditation certificate course, and 200 hour yoga teacher training course that we have talked about above. Join today if you have a spark in you, they will show you the path to a better life in yoga.
#200 hour yoga teacher training #200 hour yoga teacher training in ghaziabad #200 hour yoga teacher training in india #yoga teacher training course #yoga teacher training courses #teacher training courses
1624880003
Ab Trainings Provides Best Power BI certification training in Hyderabad, Ameerpet. Will help you learn Power BI concepts like Microsoft Power BI Desktop layouts, BI reports, dashboards, Power BI DAX commands, and functions. In this Power BI course, you will explore to experiment, fix, prepare, and present data quickly and easily.
Microsoft Power BI classroom, Online training in Power BI with Power BI Desktop, Data Modeling, Visualization, DAX, Power BI Service and Live Project, Power Bi Online Classes, Power Bi Certification, Power Bi Job Support, Power Bi Proxy, Power Bi Coaching Center, Power bI Training Institute , POWER BI SERVICE/SERVER/WORK SPACE , Corporate Training’s in Hyderabad,Ameerpet,Bangalore, Pune,Chennai,Delhi,Noida,Kerala,india,USA,UK,Canada,Dubai,Middle East,Japan,Germany,Switzerland, Austria,Spain,Australia,Malaysia,Italy,South Africa, Saudi Arabia,Singapore,China, Russia, Ukraine,
Power BI training in Hyderabad will help you get the most out of Online Power BI Training, enabling you to solve business problems and improve operations. This Power Bi Online course helps you master the development of dashboards from published reports, discover better insight from the data, & create practical recipes on the various tasks that you can do with Microsoft Power BI Training in Hyderabad
#power bi training hyderabad #microsoft power bi training in hyderabad #microsoft power bi classroom training in hyderabad #top power bi course training institute in hyderabad #power bi certification training in hyderabad #power bi online training
1649978400
Hoy vamos a aprender cómo hacer operaciones CRUD en JavaScript creando una aplicación Todo. Empecemos 🔥
Esta es la aplicación que estamos haciendo hoy:
CRUD significa -
CRUD es un tipo de mecanismo que le permite crear datos, leer datos, editarlos y eliminar esos datos. En nuestro caso, vamos a crear una aplicación Todo, por lo que tendremos 4 opciones para crear tareas, leer tareas, actualizar tareas o eliminar tareas.
Antes de comenzar el tutorial, primero, comprendamos los principios CRUD. Para eso, creemos una aplicación de redes sociales muy, muy simple.
Para este proyecto, seguiremos los siguientes pasos:
Dentro de la etiqueta del cuerpo, crea un div con un nombre de clase .container
. Ahí tendremos 2 secciones, .left
y .right
👇
<body>
<h1>Social Media App</h1>
<div class="container">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
En el lado izquierdo, crearemos nuestras publicaciones. En el lado derecho, podemos ver, actualizar y eliminar nuestras publicaciones. Ahora, crea un formulario dentro de la etiqueta div .left 👇
<div class="left">
<form id="form">
<label for="post"> Write your post here</label>
<br><br>
<textarea name="post" id="input" cols="30" rows="10"></textarea>
<br> <br>
<div id="msg"></div>
<button type="submit">Post</button>
</form>
</div>
Escribe este código dentro del HTML para que podamos mostrar nuestra publicación en el lado derecho 👇
<div class="right">
<h3>Your posts here</h3>
<div id="posts"></div>
</div>
A continuación, insertaremos el CDN font-awesome dentro de la etiqueta de encabezado para usar sus fuentes en nuestro proyecto 👇
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />
Ahora, vamos a hacer algunas publicaciones de muestra con íconos de eliminar y editar. Escribe este código dentro del div con el id #posts: 👇
<div id="posts">
<div>
<p>Hello world post 1</p>
<span class="options">
<i class="fas fa-edit"></i>
<i class="fas fa-trash-alt"></i>
</span>
</div>
<div >
<p>Hello world post 2</p>
<span class="options">
<i class="fas fa-edit"></i>
<i class="fas fa-trash-alt"></i>
</span>
</div>
</div>
El resultado hasta ahora se ve así:
Mantengámoslo simple. Escribe estos estilos dentro de tu hoja de estilo: 👇
body {
font-family: sans-serif;
margin: 0 50px;
}
.container {
display: flex;
gap: 50px;
}
#posts {
width: 400px;
}
i {
cursor: pointer;
}
Ahora, escribe estos estilos para los íconos de opción y div posteriores: 👇
#posts div {
display: flex;
align-items: center;
justify-content: space-between;
}
.options {
display: flex;
gap: 25px;
}
#msg {
color: red;
}
Los resultados hasta ahora se ven así: 👇
De acuerdo con este diagrama de flujo, seguiremos adelante con el proyecto. No te preocupes, te explicaré todo en el camino. 👇
Primero, apuntemos a todos los selectores de ID del HTML en JavaScript. Así: 👇
let form = document.getElementById("form");
let input = document.getElementById("input");
let msg = document.getElementById("msg");
let posts = document.getElementById("posts");
Luego, cree un detector de eventos de envío para el formulario para que pueda evitar el comportamiento predeterminado de nuestra aplicación. Al mismo tiempo, crearemos una función llamada formValidation
. 👇
form.addEventListener("submit", (e) => {
e.preventDefault();
console.log("button clicked");
formValidation();
});
let formValidation = () => {};
Ahora, vamos a hacer una declaración if else dentro de nuestra formValidation
función. Esto nos ayudará a evitar que los usuarios envíen campos de entrada en blanco. 👇
let formValidation = () => {
if (input.value === "") {
msg.innerHTML = "Post cannot be blank";
console.log("failure");
} else {
console.log("successs");
msg.innerHTML = "";
}
};
Aquí está el resultado hasta ahora: 👇
Como puede ver, también aparecerá un mensaje si el usuario intenta enviar el formulario en blanco.
Cualesquiera que sean los datos que obtengamos de los campos de entrada, los almacenaremos en un objeto. Vamos a crear un objeto llamado data
. Y crea una función llamada acceptData
: 👇
let data = {};
let acceptData = () => {};
La idea principal es que, usando la función, recopilamos datos de las entradas y los almacenamos en nuestro objeto llamado data
. Ahora terminemos de construir nuestra acceptData
función.
let acceptData = () => {
data["text"] = input.value;
console.log(data);
};
Además, necesitamos que la acceptData
función funcione cuando el usuario haga clic en el botón Enviar. Para eso, activaremos esta función en la instrucción else de nuestra formValidation
función. 👇
let formValidation = () => {
if (input.value === "") {
// Other codes are here
} else {
// Other codes are here
acceptData();
}
};
Cuando ingresamos datos y enviamos el formulario, en la consola podemos ver un objeto que contiene los valores de entrada de nuestro usuario. Así: 👇
Para publicar nuestros datos de entrada en el lado derecho, necesitamos crear un elemento div y agregarlo al div de publicaciones. Primero, creemos una función y escribamos estas líneas: 👇
let createPost = () => {
posts.innerHTML += ``;
};
Los acentos graves son literales de plantilla. Funcionará como una plantilla para nosotros. Aquí, necesitamos 3 cosas: un div principal, la entrada en sí y el div de opciones que lleva los íconos de edición y eliminación. Terminemos nuestra función 👇
let createPost = () => {
posts.innerHTML += `
<div>
<p>${data.text}</p>
<span class="options">
<i onClick="editPost(this)" class="fas fa-edit"></i>
<i onClick="deletePost(this)" class="fas fa-trash-alt"></i>
</span>
</div>
`;
input.value = "";
};
En nuestra acceptdata
función, activaremos nuestra createPost
función. Así: 👇
let acceptData = () => {
// Other codes are here
createPost();
};
El resultado hasta ahora: 👇
Hasta ahora todo bien chicos, casi hemos terminado con el proyecto 1.
Para eliminar una publicación, en primer lugar, creemos una función dentro de nuestro archivo javascript:
let deletePost = (e) => {};
A continuación, activamos esta deletePost
función dentro de todos nuestros íconos de eliminación usando un atributo onClick. Escribirá estas líneas en HTML y en el literal de la plantilla. 👇
<i onClick="deletePost(this)" class="fas fa-trash-alt"></i>
La this
palabra clave se referirá al elemento que disparó el evento. en nuestro caso, el this
se refiere al botón eliminar.
Mire con cuidado, el padre del botón Eliminar es el tramo con opciones de nombre de clase. El padre del lapso es el div. Entonces, escribimos parentElement
dos veces para que podamos saltar del ícono de eliminar al div y apuntarlo directamente para eliminarlo.
Terminemos nuestra función. 👇
let deletePost = (e) => {
e.parentElement.parentElement.remove();
};
El resultado hasta ahora: 👇
Para editar una publicación, en primer lugar, creemos una función dentro de nuestro archivo JavaScript:
let editPost = (e) => {};
A continuación, activamos esta editPost
función dentro de todos nuestros íconos de edición usando un atributo onClick. Escribirá estas líneas en HTML y en el literal de la plantilla. 👇
<i onClick="editPost(this)" class="fas fa-edit"></i>
La this
palabra clave se referirá al elemento que disparó el evento. En nuestro caso, el this
se refiere al botón editar.
Mire con cuidado, el padre del botón de edición es el tramo con opciones de nombre de clase. El padre del lapso es el div. Entonces, escribimos parentElement
dos veces para que podamos saltar del ícono de edición al div y apuntarlo directamente para eliminarlo.
Luego, cualquier dato que esté dentro de la publicación, lo traemos de vuelta al campo de entrada para editarlo.
Terminemos nuestra función. 👇
let editPost = (e) => {
input.value = e.parentElement.previousElementSibling.innerHTML;
e.parentElement.parentElement.remove();
};
El resultado hasta ahora: 👇
Felicitaciones a todos por completar el proyecto 1. Ahora, ¡tómense un pequeño descanso!
Cómo hacer una aplicación de tareas pendientes usando operaciones CRUD
Comencemos a hacer el proyecto 2, que es una aplicación To-Do.
Para este proyecto, seguiremos los siguientes pasos:
Escribe este código de inicio dentro del archivo HTML: 👇
<div class="app">
<h4 class="mb-3">TODO App</h4>
<div id="addNew" data-bs-toggle="modal" data-bs-target="#form">
<span>Add New Task</span>
<i class="fas fa-plus"></i>
</div>
</div>
El div con una identificación addNew
es el botón que abrirá el modal. El intervalo se mostrará en el botón. El i
es el ícono de font-awesome.
Vamos a usar bootstrap para hacer nuestro modal. Usaremos el modal para agregar nuevas tareas. Para eso, agregue el enlace CDN de arranque dentro de la etiqueta principal. 👇
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"
></script>
Para ver las tareas creadas, usaremos un div con una tarea de identificación, dentro del div con la aplicación de nombre de clase. 👇
<h5 class="text-center my-3">Tasks</h5>
<div id="tasks"></div>
Inserte el CDN font-awesome dentro de la etiqueta principal para usar fuentes en nuestro proyecto 👇
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />
Copie y pegue el código a continuación que proviene del modal de arranque. Lleva un formulario con 3 campos de entrada y un botón de envío. Si lo desea, puede buscar en el sitio web de Bootstrap escribiendo 'modal' en la barra de búsqueda.
<!-- Modal -->
<form
class="modal fade"
id="form"
tabindex="-1"
aria-labelledby="exampleModalLabel"
aria-hidden="true"
>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add New Task</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">
<p>Task Title</p>
<input type="text" class="form-control" name="" id="textInput" />
<div id="msg"></div>
<br />
<p>Due Date</p>
<input type="date" class="form-control" name="" id="dateInput" />
<br />
<p>Description</p>
<textarea
name=""
class="form-control"
id="textarea"
cols="30"
rows="5"
></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
Close
</button>
<button type="submit" id="add" class="btn btn-primary">Add</button>
</div>
</div>
</div>
</form>
El resultado hasta ahora: 👇
Hemos terminado con la configuración del archivo HTML. Comencemos el CSS.
Agregue estos estilos en el cuerpo para que podamos mantener nuestra aplicación en el centro exacto de la pantalla.
body {
font-family: sans-serif;
margin: 0 50px;
background-color: #e5e5e5;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
Apliquemos estilo al div con la aplicación classname. 👇
.app {
background-color: #fff;
width: 300px;
height: 500px;
border: 5px solid #abcea1;
border-radius: 8px;
padding: 15px;
}
El resultado hasta ahora: 👇
Ahora, diseñemos el botón con el id addNew
. 👇
#addNew {
display: flex;
justify-content: space-between;
align-items: center;
background-color: rgba(171, 206, 161, 0.35);
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
}
.fa-plus {
background-color: #abcea1;
padding: 3px;
border-radius: 3px;
}
El resultado hasta ahora: 👇
Si hace clic en el botón, el modal aparece así: 👇
En el archivo JavaScript, en primer lugar, seleccione todos los selectores del HTML que necesitamos usar. 👇
let form = document.getElementById("form");
let textInput = document.getElementById("textInput");
let dateInput = document.getElementById("dateInput");
let textarea = document.getElementById("textarea");
let msg = document.getElementById("msg");
let tasks = document.getElementById("tasks");
let add = document.getElementById("add");
No podemos permitir que un usuario envíe campos de entrada en blanco. Entonces, necesitamos validar los campos de entrada. 👇
form.addEventListener("submit", (e) => {
e.preventDefault();
formValidation();
});
let formValidation = () => {
if (textInput.value === "") {
console.log("failure");
msg.innerHTML = "Task cannot be blank";
} else {
console.log("success");
msg.innerHTML = "";
}
};
Además, agregue esta línea dentro del CSS:
#msg {
color: red;
}
El resultado hasta ahora: 👇
Como puede ver, la validación está funcionando. El código JavaScript no permite que el usuario envíe campos de entrada en blanco; de lo contrario, verá un mensaje de error.
Independientemente de las entradas que escriba el usuario, debemos recopilarlas y almacenarlas en el almacenamiento local.
Primero, recopilamos los datos de los campos de entrada, usando la función named acceptData
y una matriz llamada data
. Luego los empujamos dentro del almacenamiento local así: 👇
let data = [];
let acceptData = () => {
data.push({
text: textInput.value,
date: dateInput.value,
description: textarea.value,
});
localStorage.setItem("data", JSON.stringify(data));
console.log(data);
};
También tenga en cuenta que esto nunca funcionará a menos que invoque la función acceptData
dentro de la declaración else de la validación del formulario. Síguenos aquí: 👇
let formValidation = () => {
// Other codes are here
else {
// Other codes are here
acceptData();
}
};
Es posible que haya notado que el modal no se cierra automáticamente. Para resolver esto, escribe esta pequeña función dentro de la instrucción else de la validación del formulario: 👇
let formValidation = () => {
// Other codes are here
else {
// Other codes are here
acceptData();
add.setAttribute("data-bs-dismiss", "modal");
add.click();
(() => {
add.setAttribute("data-bs-dismiss", "");
})();
}
};
Si abre las herramientas de desarrollo de Chrome, vaya a la aplicación y abra el almacenamiento local. Puedes ver este resultado: 👇
Para crear una nueva tarea, necesitamos crear una función, usar literales de plantilla para crear los elementos HTML y usar un mapa para insertar los datos recopilados del usuario dentro de la plantilla. Síguenos aquí: 👇
let createTasks = () => {
tasks.innerHTML = "";
data.map((x, y) => {
return (tasks.innerHTML += `
<div id=${y}>
<span class="fw-bold">${x.text}</span>
<span class="small text-secondary">${x.date}</span>
<p>${x.description}</p>
<span class="options">
<i onClick= "editTask(this)" data-bs-toggle="modal" data-bs-target="#form" class="fas fa-edit"></i>
<i onClick ="deleteTask(this);createTasks()" class="fas fa-trash-alt"></i>
</span>
</div>
`);
});
resetForm();
};
También tenga en cuenta que la función nunca se ejecutará a menos que la invoque dentro de la acceptData
función, así: 👇
let acceptData = () => {
// Other codes are here
createTasks();
};
Una vez que hayamos terminado de recopilar y aceptar datos del usuario, debemos borrar los campos de entrada. Para eso creamos una función llamada resetForm
. Síguenos: 👇
let resetForm = () => {
textInput.value = "";
dateInput.value = "";
textarea.value = "";
};
El resultado hasta ahora: 👇
Como puede ver, no hay estilos con la tarjeta. Agreguemos algunos estilos: 👇
#tasks {
display: grid;
grid-template-columns: 1fr;
gap: 14px;
}
#tasks div {
border: 3px solid #abcea1;
background-color: #e2eede;
border-radius: 6px;
padding: 5px;
display: grid;
gap: 4px;
}
Dale estilo a los botones de editar y eliminar con este código: 👇
#tasks div .options {
justify-self: center;
display: flex;
gap: 20px;
}
#tasks div .options i {
cursor: pointer;
}
El resultado hasta ahora: 👇
Mire aquí cuidadosamente, agregué 3 líneas de código dentro de la función.
let deleteTask = (e) => {
e.parentElement.parentElement.remove();
data.splice(e.parentElement.parentElement.id, 1);
localStorage.setItem("data", JSON.stringify(data));
console.log(data);
};
Ahora cree una tarea ficticia e intente eliminarla. El resultado hasta ahora se ve así: 👇
Mire aquí cuidadosamente, agregué 5 líneas de código dentro de la función.
let editTask = (e) => {
let selectedTask = e.parentElement.parentElement;
textInput.value = selectedTask.children[0].innerHTML;
dateInput.value = selectedTask.children[1].innerHTML;
textarea.value = selectedTask.children[2].innerHTML;
deleteTask(e);
};
Ahora, intente crear una tarea ficticia y edítela. El resultado hasta ahora: 👇
Si actualiza la página, notará que todos sus datos han desaparecido. Para resolver ese problema, ejecutamos un IIFE (expresión de función invocada inmediatamente) para recuperar los datos del almacenamiento local. Síguenos: 👇
(() => {
data = JSON.parse(localStorage.getItem("data")) || [];
console.log(data);
createTasks();
})();
Ahora los datos aparecerán incluso si actualiza la página.
Felicitaciones por completar con éxito este tutorial. Ha aprendido a crear una aplicación de lista de tareas mediante operaciones CRUD. Ahora, puede crear su propia aplicación CRUD usando este tutorial.
Aquí está tu medalla por leer hasta el final. ❤️
Fuente: https://www.freecodecamp.org/news/learn-crud-operations-in-javascript-by-building-todo-app/