Real-time Kanban board with Vue.js and Hamoni Sync

Real-time Kanban board with Vue.js and Hamoni Sync

Real-time kanban board built with Vue.js and powered by Hamoni Sync .realtime-kanban-vue. Real-time kanban board built with Vue.js and powered by Hamoni Sync. Build Setup. # install dependencies npm install

A kanban board is a workflow visualization tool that enables you to optimize the flow of your work. In this post, I’ll show you how to build a real-time kanban board in Vue.

To follow along you’ll need to have some knowledge about Vue and its single file component. You’ll also need the following tools:

  1. Node.js & npm (follow this link to download an installer for your OS)
  2. Vue CLI. If you don’t have this, run npm install -g vue-cli in the command line to install it.

If you have no knowledge about Vue, you can read my previous post before continuing with this one.

Setup the project

We’ll set up the project using Vue CLI, which is a simple command line interface (CLI) for scaffolding Vue.js projects. Open the terminal and run vue init webpack-simple realtime-kanban-board. You'll get some prompts, accept the default values by pressing enter and select y when asked if you want to use saas. Before running the command, you can change realtime-kanban-board to your preferred project name. Once this is set up, run the following command to install the dependencies from the scaffolded template:

cd realtime-kanban-board
npm install

We will be using vue-kanban as a kanban board component with drag and drop features. We’ll also use Hamoni Sync to store and synchronise the application state in real-time. They’re both on npm and we’ll install them by running the following command:

npm install vue-kanban hamoni-sync

We need some extra packages for Babel. Install them by running the following command:

npm install --save-dev babel-plugin-transform-runtime babel-preset-stage-2
Add vue-kanban

We’ve scaffolded the application which now contains the necessary files to run the application. Open the file src/App.vue with your text editor (or IDE) and replace its content with the following:

<template>
  <div id="app">
    <kanban-board :stages="stages" :blocks="blocks" @update-block="updateBlock">
      <div v-for="block in blocks" :slot="block.id" :key="block.id">
        <div>
          <strong>id:</strong> {{ block.id }}
        </div>
        <div>
          {{ block.title }}
        </div>
      </div>
    </kanban-board>
  </div>
</template>
<script>
import Vue from "vue";
import vueKanban from "vue-kanban";
import Hamoni from "hamoni-sync";
Vue.use(vueKanban);
export default {
  name: "app",
  data() {
    return {
      stages: ["on-hold", "in-progress", "needs-review", "approved"],
      blocks: [],
      listPrimitive: null
    };
  },
  methods: {
    updateBlock(id, status) {
      //TODO: add code to update the block
    }
  },
};
</script>
<style lang="scss">
@import "./assets/kanban.scss";
</style>

The code above uses the kanban-board component with 2 props, stagesand blocks. The stages prop defines the columns for the board, and blocks contains the data representing task item placed on a column. The @update-block event is triggered when a block is moved from one stage to another. We will use this event to update the board in real-time.

Add Hamoni Sync

We’ve added the necessary code to render a kanban board to the page. In this section, we’ll setup Hamoni Sync to store and synchronise the data for blocks. Hamoni Sync is a service which enables you to synchronise your application state in real-time.

To use Hamoni Sync, we need to initialise it and connect to Hamoni server. To do this we need an account and application ID. Follow these steps to create an application in Hamoni.

  1. Register and login to Hamoni dashboard
  2. Enter your preferred application name in the text field and click the create button. This should create the app and display it in the application list section.
  3. Click the button “Show Account ID” to see your account ID.

Add the following code to App.vue on line 35.

mounted: function() {
let hamoni = new Hamoni("ACCOUNT_ID", "APP_ID");
hamoni
    .connect()
    .then(() => {
    hamoni
        .get("blocks")
        .then(listPrimitive => {
            this.listPrimitive = listPrimitive;
            this.blocks = listPrimitive.getAll();
            listPrimitive.onItemUpdated(item => {
                //update the item at item.index
                this.blocks.splice(item.index, 1, item.value);
            });
        })
        .catch(error => {
        if (error == "Error getting state from server") {
            hamoni
            .createList("blocks", blocks)
            .then(listPrimitive => {
                this.listPrimitive = listPrimitive;
                this.blocks = listPrimitive.getAll();
                listPrimitive.onItemUpdated(item => {
                    //update the item at item.index
                    this.blocks.splice(item.index, 1, item.value);
                });
            })
            .catch(console.log);
        }
        });
    })
    .catch(console.log);
}

Add the following before the closing </script> tag:

const blocks = [
  {
    id: 0,
    status: "approved",
    title: "Buy coffee machine"
  },
  {
    id: 1,
    status: "in-progress",
    title: "Find better AirBnB options"
  },
  {
    id: 2,
    status: "on-hold",
    title: "Approve Q3 budget"
  },
  {
    id: 3,
    status: "approved",
    title: "Travel to Colombia"
  },
  {
    id: 4,
    status: "needs-review",
    title: "Add Redux to the app"
  },
  {
    id: 5,
    status: "approved",
    title: "Well, Sleep all day 👩‍🎤"
  },
  {
    id: 6,
    status: "in-progress",
    title: "Find language exchange partner"
  }
];

We initialised it by calling new Hamoni("ACCOUNT_ID", "APP_ID");. Replace the string placeholders with your account and application ID which you will get from Hamoni dashboard. Then we connected the app using hamoni.connect(). We retrieved the data by calling hamoni.get() with the name of the application state stored on Hamoni Sync. If it doesn't exist yet, we'll create it and then add function to update Vue's state when an item is updated. This is achieved by calling onItemUpdated() with code to update the block on item.index. Hamoni Sync provides what is called a list primitive which we've used here by calling hamoni.createList() and passing it an array.

Now we need to update the state on Hamoni when a block is moved from one stage to another. We’ll update the function updateBlock(id, status)which we added earlier

methods: {
    updateBlock(id, status) {
        let block = this.blocks[id];
        this.listPrimitive.update(id, { id, title: "block.title, status });"
    }
},

This code tells sync to update the state and once this is done, it’ll be synchronised to all connected clients/devices.

That is all the code that’s needed. Now run the app by running npm run dev from the command line and this will launch the web app in your default browser.

There you have it 🚀A real-time kanban board.

That’s a Wrap!

So we’ve built a real-time kanban board using vue-kanban and Hamoni Sync. Hamoni Sync makes it easy to integrate real-time features in your applications. You can get the completed code on GitHub. Happy coding! 👍

Resources

JavaScript Tutorial: if-else Statement in JavaScript

JavaScript Tutorial: if-else Statement in JavaScript

This JavaScript tutorial is a step by step guide on JavaScript If Else Statements. Learn how to use If Else in javascript and also JavaScript If Else Statements. if-else Statement in JavaScript. JavaScript's conditional statements: if; if-else; nested-if; if-else-if. These statements allow you to control the flow of your program's execution based upon conditions known only during run time.

Decision Making in programming is similar to decision making in real life. In programming also we face some situations where we want a certain block of code to be executed when some condition is fulfilled.
A programming language uses control statements to control the flow of execution of the program based on certain conditions. These are used to cause the flow of execution to advance and branch based on changes to the state of a program.

JavaScript’s conditional statements:

  • if
  • if-else
  • nested-if
  • if-else-if

These statements allow you to control the flow of your program’s execution based upon conditions known only during run time.

  • if: if statement is the most simple decision making statement. It is used to decide whether a certain statement or block of statements will be executed or not i.e if a certain condition is true then a block of statement is executed otherwise not.
    Syntax:
if(condition) 
{
   // Statements to execute if
   // condition is true
}

Here, condition after evaluation will be either true or false. if statement accepts boolean values – if the value is true then it will execute the block of statements under it.
If we do not provide the curly braces ‘{‘ and ‘}’ after if( condition ) then by default if statement will consider the immediate one statement to be inside its block. For example,

if(condition)
   statement1;
   statement2;

// Here if the condition is true, if block 
// will consider only statement1 to be inside 
// its block.

Flow chart:

Example:

<script type = "text/javaScript"> 

// JavaScript program to illustrate If statement 

var i = 10; 

if (i > 15) 
document.write("10 is less than 15"); 

// This statement will be executed 
// as if considers one statement by default 
document.write("I am Not in if"); 

< /script> 

Output:

I am Not in if
  • if-else: The if statement alone tells us that if a condition is true it will execute a block of statements and if the condition is false it won’t. But what if we want to do something else if the condition is false. Here comes the else statement. We can use the else statement with if statement to execute a block of code when the condition is false.
    Syntax:
if (condition)
{
    // Executes this block if
    // condition is true
}
else
{
    // Executes this block if
    // condition is false
}


Example:

<script type = "text/javaScript"> 

// JavaScript program to illustrate If-else statement 

var i = 10; 

if (i < 15) 
document.write("10 is less than 15"); 
else
document.write("I am Not in if"); 

< /script> 

Output:

i is smaller than 15
  • nested-if A nested if is an if statement that is the target of another if or else. Nested if statements means an if statement inside an if statement. Yes, JavaScript allows us to nest if statements within if statements. i.e, we can place an if statement inside another if statement.
    Syntax:
if (condition1) 
{
   // Executes when condition1 is true
   if (condition2) 
   {
      // Executes when condition2 is true
   }
}

Example:

<script type = "text/javaScript"> 

// JavaScript program to illustrate nested-if statement 

var i = 10; 

if (i == 10) { 

// First if statement 
if (i < 15) 
	document.write("i is smaller than 15"); 

// Nested - if statement 
// Will only be executed if statement above 
// it is true 
if (i < 12) 
	document.write("i is smaller than 12 too"); 
else
	document.write("i is greater than 15"); 
} 
< /script> 

Output:

i is smaller than 15
i is smaller than 12 too
  • if-else-if ladder Here, a user can decide among multiple options.The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will be executed.
if (condition)
    statement;
else if (condition)
    statement;
.
.
else
    statement;


Example:

<script type = "text/javaScript"> 
// JavaScript program to illustrate nested-if statement 

var i = 20; 

if (i == 10) 
document.wrte("i is 10"); 
else if (i == 15) 
document.wrte("i is 15"); 
else if (i == 20) 
document.wrte("i is 20"); 
else
document.wrte("i is not present"); 
< /script> 

Output:

i is 20

How to Retrieve full Profile of LinkedIn User using Javascript

How to Retrieve full Profile of LinkedIn User using Javascript

I am trying to retrieve the full profile (especially job history and educational qualifications) of a linkedin user via the Javascript (Fetch LinkedIn Data Using JavaScript)

Here we are fetching LinkedIn data like Username, Email and other fields using JavaScript SDK.

Here we have 2 workarounds.

  1. Configuration of linkedIn developer api
  2. Javascript Code to fetch records

Configuration of linkedIn developer api

In order to fetch records, first we need to create developer api in linkedin which will act as token/identity while fetching data from other linkedin accounts.

So to create api, navigate to https://linkedin.com/developer/apps and click on 'Create Application'.

After navigating, fill in details like name, description and other required fields and then submit.

As we submit, it will create Client ID and Client Secret shown below, which we will be using in our code while communicating to fetch records from other LinkedIn account.

Note: We need to provide localhost Url here under Oauth 2.0. I am using my localhost, but you can probably use other production URLs under Oauth 2.0 where your app is configured. It will make your api  consider the Url as trusted which fetching records.

Javascript Code to fetch records

For getting user details like first name, last name,User image can be written as,

<script type="text/javascript" src="https://platform.linkedin.com/in.js">  
    api_key: XXXXXXX //Client ID  
    onLoad: OnLinkedInFrameworkLoad //Method that will be called on page load  
    authorize: true  
</script>  
<script type="text/javascript">  
    function OnLinkedInFrameworkLoad() {  
        IN.Event.on(IN, "auth", OnLinkedInAuth);  
    }  
  
    function OnLinkedInAuth() {  
        IN.API.Profile("me").result(ShowProfileData);  
    }  
  
    function ShowProfileData(profiles) {  
        var member = profiles.values[0];  
        var id = member.id;  
        var firstName = member.firstName;  
        var lastName = member.lastName;  
        var photo = member.pictureUrl;  
        var headline = member.headline;  
        //use information captured above  
        var stringToBind = "<p>First Name: " + firstName + " <p/><p> Last Name: " + lastName + "<p/><p>User ID: " + id + " and Head Line Provided: " + headline + "<p/>"  
        document.getElementById('profiles').innerHTML = stringToBind;  
    }  
</script>    

Kindly note we need to include 'https://platform.linkedin.com/in.js' as src under script type as it will act on this Javascript SDK provided by Linkedin.

In the same way we can also fetch records of any organization with the companyid as keyword.

<head>  
    <script type="text/javascript" src="https://platform.linkedin.com/in.js">  
        api_key: XXXXXXX ////Client ID  
        onLoad: onLinkedInLoad  
        authorize: true  
    </script>  
</head>  
  
<body>  
    <div id="displayUpdates"></div>  
    <script type="text/javascript">  
        function onLinkedInLoad() {  
            IN.Event.on(IN, "auth", onLinkedInAuth);  
            console.log("On auth");  
        }  
  
        function onLinkedInAuth() {  
            var cpnyID = XXXXX; //the Company ID for which we want updates  
            IN.API.Raw("/companies/" + cpnyID + "/updates?event-type=status-update&start=0&count=10&format=json").result(displayCompanyUpdates);  
            console.log("After auth");  
        }  
  
        function displayCompanyUpdates(result) {  
            var div = document.getElementById("displayUpdates");  
            var el = "<ul>";  
            var resValues = result.values;  
            for (var i in resValues) {  
                var share = resValues[i].updateContent.companyStatusUpdate.share;  
                var isContent = share.content;  
                var isTitled = isContent,  
                    isLinked = isContent,  
                    isDescription = isContent,  
                    isThumbnail = isContent,  
                    isComment = isContent;  
                if (isTitled) {  
                    var title = isContent.title;  
                } else {  
                    var title = "News headline";  
                }  
                var comment = share.comment;  
                if (isLinked) {  
                    var link = isContent.shortenedUrl;  
                } else {  
                    var link = "#";  
                }  
                if (isDescription) {  
                    var description = isContent.description;  
                } else {  
                    var description = "No description";  
                }  
                /* 
                if (isThumbnailz) { 
                var thumbnailUrl = isContent.thumbnailUrl; 
                } else { 
                var thumbnailUrl = "http://placehold.it/60x60"; 
                } 
                */  
                if (share) {  
                    var content = "<a target='_blank' href=" + link + ">" + comment + "</a><br>";  
                    //el += "<li><img src='" + thumbnailUrl + "' alt=''>" + content + "</li>";  
                    el += "<li><div>" + content + "</div></li>";  
                }  
                console.log(share);  
            }  
            el += "</ul>";  
            document.getElementById("displayUpdates").innerHTML = el;  
        }  
    </script>  
</body>  

We can get multiple metadata while fetching records for any any organization. We can get company updates as shown below.

Conclusion

We can also fetch any company specific data like company job updates/post, total likes, comments, and number of views along with a lot of metadata we can fetch which I have shown below.

Thank you for reading !

Making a Game in VueJS using Vuex | VueJS Tutorial

Making a Game in VueJS using Vuex | VueJS Tutorial

Today we create a Game in VueJS using Vuex to manage our state. This is an open source community driven game and I would love for you to get involved. We explore the game loop, upgrades, levelling and much more

Today we create a Game in VueJS using Vuex to manage our state. This is an open source community driven game and I would love for you to get involved. We explore the game loop, upgrades, levelling and much more. We looking into VueJS lifecycle methods as well as Vuex mutations, getters and state.

A Javascript Project

Day 15 #31Days31Videos