<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Avneesh</title>
    <description>The latest articles on DEV Community by Avneesh (@krillxox).</description>
    <link>https://dev.to/krillxox</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F483316%2Feaa1a228-1f91-4ecd-ae99-55be4a497c91.jpeg</url>
      <title>DEV Community: Avneesh</title>
      <link>https://dev.to/krillxox</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/krillxox"/>
    <language>en</language>
    <item>
      <title>Make your first Electron project with time table generator</title>
      <dc:creator>Avneesh</dc:creator>
      <pubDate>Tue, 06 Oct 2020 08:56:19 +0000</pubDate>
      <link>https://dev.to/krillxox/make-your-first-electron-project-with-time-table-generator-36n4</link>
      <guid>https://dev.to/krillxox/make-your-first-electron-project-with-time-table-generator-36n4</guid>
      <description>&lt;p&gt;We'll create a time table generator app in electron framework. This app will be able to generate a timetable that can be exported as .xlsx and can be stored in the system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dependencies
&lt;/h2&gt;

&lt;p&gt;To get started, make sure you have installed electron, node js, and npm.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the app
&lt;/h2&gt;

&lt;p&gt;Open terminal and type npx create-electron-app time-table-generator. You will get output like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4KtMXcMZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pmxoqaoanmpu7wjink4i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4KtMXcMZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pmxoqaoanmpu7wjink4i.png" alt="Creating app using npx"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  index.html
&lt;/h2&gt;

&lt;p&gt;To make a timetable, we need some information number of classes and the subject name. For that, we will create a label and select box like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I3G5vKGc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wb430mj2q5njrxi1iw4z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I3G5vKGc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wb430mj2q5njrxi1iw4z.png" alt="Taking data using select"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wyobwuCY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0fnyf2a5frf2dpw26nzq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wyobwuCY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0fnyf2a5frf2dpw26nzq.png" alt="In action"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we need the subject names. For this, we'll generate input fields dynamically. This can be done by javascript. That's it, now we'll work in javascript file for generating time table.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating table through javascript file
&lt;/h2&gt;

&lt;p&gt;Now create a new javascript file. We need to add the subject names mentioned before in an array. Here's the way to do this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Byi3eRoI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/mtfv3sna66dol06ivjpz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Byi3eRoI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/mtfv3sna66dol06ivjpz.png" alt="Adding subject name in array"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE: This function is invoked when we click on '+' button for new input field to enter new subject name.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ubvvSbRB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/55ni74e4415wtyu9hw1p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ubvvSbRB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/55ni74e4415wtyu9hw1p.png" alt="Input field for subject name"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We'll store the above data in local storage(will later discuss why I used local storage to store data). Now we'll create a function which will generate the time table and display on the next page and to do that we will use:&lt;/p&gt;

&lt;pre&gt;window.location.replace("02.html") //to store in localstorage
localStorage.setItem("time", time)&lt;/pre&gt;

&lt;pre&gt;var nClass = Number(localStorage.getItem("nClass")) // to get data from localstorage
for (var i = 1; i &amp;lt;= 5; i++) {
        html += "&lt;tbody&gt;&lt;tr&gt;
&lt;th&gt;" + days[i-1] + '&lt;/th&gt;' //days is array containing days of the week.
        for (let j = 1; j &amp;lt; nClass; j++) {
            if (j == nClass/2) {
                html += '&lt;td&gt;' + subjects[Math.floor(Math.random() * subjects.length + 0)] + '&lt;/td&gt;' + '&lt;td&gt; Lunch &lt;/td&gt;' + '&lt;td&gt;' + subjects[Math.floor(Math.random() * subjects.length + 0)] + '&lt;/td&gt;'
            } else {
                html += '&lt;td&gt;' + subjects[Math.floor(Math.random() * subjects.length + 0)] + '&lt;/td&gt;'
            }
        }
    html += "&lt;/tr&gt;&lt;/tbody&gt;"
  }
  html += ""
  document.getElementById("tt").innerHTML = html;&lt;/pre&gt;

&lt;h2&gt;
  
  
  Displaying table on next page
&lt;/h2&gt;

&lt;p&gt;To display the table on the next page, we'll create a new HTML file and add that function name in on-load in body tag.&lt;br&gt;
Now here comes the role of local storage, in order to get data from previous page we stored it in local storage. Now we can use that data stored to make table.&lt;/p&gt;

&lt;p&gt;That's it, now start the app by typing in &lt;code&gt;npm start&lt;/code&gt; in the terminal:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4YVS07nU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v5t0d3j3hg3oxgbys4j2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4YVS07nU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v5t0d3j3hg3oxgbys4j2.png" alt="Time table generator running"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dyBZEcSb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oizceqvrwxcqu9qtr3st.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dyBZEcSb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oizceqvrwxcqu9qtr3st.png" alt="Timetable"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus
&lt;/h2&gt;

&lt;p&gt;If you want to export that as .xlsx we'll use table2excel.js. For that, you need to install its dependencies. Open the terminal and type npm install bootstrap jquery popper.js xlsx file-saverjs. Make sure to include them in order(bootstrap, jquery then table2excel):&lt;/p&gt;

&lt;p&gt;Now add this jQuery function:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s----orK6oO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/086keq4stzygcsusdq2i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s----orK6oO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/086keq4stzygcsusdq2i.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can play around and can add more features. This project can be found at: &lt;a href="https://github.com/krillxox/time-table-generator"&gt;time-table-generator&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>html</category>
      <category>javascript</category>
      <category>electron</category>
      <category>jquery</category>
    </item>
  </channel>
</rss>
