Extensions

Vue tutorial

How to use our JavaScript based Gantt chart components in a Vue app.

Introduction

DlhSoft has developed Gantt Chart Hyper Library using pure JavaScript (and has also introduced TypeScript definitions for its components later.) That means the components can also be used when building Web apps using higher level frameworks, such as Vue (at the time of writing this text — version 2.6), and we have defined wrapper components to help you out reaching this goal.

If you're running even newer versions of the referrenced software (that may have been recently published), don't worry, most probably all the commands will continue to run with very little or no changes at all. Also note that commands presented in this tutorial are for Windows based development systems, but macOS and Linux can also be used (and differences are indicated wherever they matter.)

TypeScript and class style component syntax considerations

If you use TypeScript and class style component syntax (such as by having created your project using vue create my-app and adding TypeScript and class style component syntax options manually) you can use DlhSoft Vue-TypeScript component extensions by following the steps provided in a separate tutorial. The current document focuses below on using plain JavaScript components instead.

Setting up your Vue app

In this tutorial we'll show how you can create a Vue app and then integrate DlhSoft Gantt chart components in its code. If you already have a Vue app and experience with the tools, see technical documentation instead.

Note that a Vue app can be created using the official CLI (command line interface), available for installation with npm, but here we'll simply create an app folder and some files in a more manual way.

  • Create an app folder

    Create a folder to host the files of your app, running the mkdir command below in Command prompt (or Terminal) after you changed the path to your root projects folder (whichever you choose.)

    
    cd projects
    mkdir my-app
    
  • Create index.html and app.js files

    Use your preferred text editor to create the following files in the folder of your application.

    Index.html
    
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>GanttChartView sample</title>
        <!-- Vue. When deploying, replace "vue/dist/vue.js" with "vue". -->
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <!-- Main app component -->
        <script type="text/babel" src="app.js"></script>
    </head>
    <body style="font-family: Roboto;">
        <h1>GanttChartView sample</h1>
        <div id="app">
            …
        </div>
    </body>
    </html>
    
    
    var app = new Vue({
        el: '#app'
    });
    

    This is a very simple Vue app that would simply displays "…" on screen. Actually, Vue itself itsn't even involved in output yet.

  • Host and test the app

    You may host the app's folder on a Web server (possibly locally, for testing purposes, to be accessed with http:// protocol), or — easier — you can open index.html file from your computer directly in a browser (using file:// protocol.)

Get DlhSoft components

Our pure JavaScript components are not enclosed in a high level package — but they are available for download as .zip or .tar files. This means that they will not update automatically, but this is, in our opinion, a more generic approach. You can surely download the most up to date archive file whenever you need to use a more recent build, however, and we encourage you to subscribe to our core product news feed to know when new features arrive.

  • Download libraries

    You can either download DlhSoft components directly as a .zip file (as stated above) and extract it yourself wherever you'd like (to be saved for further reference), or you can use npm to get them into an node_modules subfolder as you may be doing with your other packages. The difference is that you point npm to an URL rather than a package name.

    
    npm install http://DlhSoft.com/Packages/DlhSoft.GanttChartHyperLibrary.tar
    
  • Determine which scripts you need

    Open the extracted folder. In Windows, you can use explorer command, while on macOS and Linux open command should be used to view the contents of the destination folder. (Alternatively, you can run dir or ls commands to view the results directly in your Command Prompt or Terminal window; on macOS and Linux use slash / character to separate path parts.)

    
    dir node_modules\DlhSoft.GanttChartHyperLibrary
    

    The files below are available for you to use in your Vue app. The appropriate core .js (and optionally .d.ts - TypeScript definition) files are needed for the Vue extension components to work. Other files are also available inside the folder, but you can safely ignore them.

    Category Details Files
    Core JavaScript components Gantt chart, schedule chart, load chart
    PERT chart, network diagram
    DlhSoft.ProjectData.GanttChart.HTML.Controls.js, .d.ts
    DlhSoft.ProjectData.PertChart.HTML.Controls.js, .d.ts
    Optional UI enhancers Date-time picker, multi-selector combo box DlhSoft.Data.HTML.Controls.js, .d.ts
    Optional XML import/export Project serializer DlhSoft.ProjectData.GanttChart.HTML.Controls.Extras.js, .d.ts
    Vue extensions Gantt chart, schedule chart, load chart
    PERT chart, network diagram
    DlhSoft.ProjectData.GanttChart.Vue.Components.js
    DlhSoft.ProjectData.PertChart.Vue.Components.js
  • Copy the necessary files

    The files in extracted folder may not be immediately available to use in your Vue app. You need to copy the files you need into one of your app's main folders, first. (We admit that if we'd have defined a JSON package files for our product this step would have been easier, but as previously indicated, we wanted to go with a more generic approach that wouldn't depend on any specific metadata in the archives to make things work.)

    The most simple approach is to host DlhSoft files under the root app's folder. Copy the files using either Explorer or Finder, or using command lines.

    
    copy node_modules\DlhSoft.GanttChartHyperLibrary\DlhSoft.ProjectData.GanttChart.HTML.Controls.js .\
    copy node_modules\DlhSoft.GanttChartHyperLibrary\DlhSoft.ProjectData.PertChart.HTML.Controls.js .\
    copy node_modules\DlhSoft.GanttChartHyperLibrary\DlhSoft.Data.HTML.Controls.js .\
    copy node_modules\DlhSoft.GanttChartHyperLibrary\DlhSoft.ProjectData.GanttChart.Vue.Components.js .\
    copy node_modules\DlhSoft.GanttChartHyperLibrary\DlhSoft.ProjectData.PertChart.Vue.Components.js .\
    
  • Reference core and extension scripts

    Update index.html file (previously created in the root folder of your Vue project), referencing the DlhSoft core and extension script files that you need (in the HTML's head, after Vue library reference, and just above the app.js reference.)

    
    <head>
        …
        <!-- DlhSoft Gantt Chart Hyper Library core -->
        <script src="DlhSoft.Data.HTML.Controls.js"><script>
        <script src="DlhSoft.ProjectData.GanttChart.HTML.Controls.js"><script>
        <script src="DlhSoft.ProjectData.PertChart.HTML.Controls.js"><script>
        <!-- DlhSoft Gantt Chart Hyper Library extensions -->
        <script src="DlhSoft.ProjectData.GanttChart.Vue.Components.js"><script>
        <script src="DlhSoft.ProjectData.PertChart.Vue.Components.js"><script>
        …
    </head>
    
  • Use DlhSoft components in your markup

    To use Dlhsoft Vue components you simply need to place appropriately named elements in your markup files (defining the user interface of your screens), and set up the properties — items, settings, license, change — to the data you will also need to prepare for them in code. For example, replace the contents of the "app" div in index.html file that you have previously created.

    
    <div id="app">
        <gantt-chart v-bind:items="items" v-bind:settings="settings" v-bind:license="license"
                     v-on:change="onItemChanged"
                     style="min-height: 388px">
            …
        </gantt-chart>
    </div>
    

    The elements that can be used are listed below, mapped to the specific components they reference.

    Component Element Details
    GanttChartView gantt-chart Singe bar per row, e.g. project with tasks
    ScheduleChartView schedule-chart Multiple bars per row, e.g. tasks assigned to resources
    LoadChartView load-chart Allocations over time, e.g. resource load percents
    PertChartView pert-chart PERT diagram, e.g. tasks displayed as arrows
    NetworkDiagramView network-diagram Network diagram, e.g. PERT methodology
  • Set up data

    As mentioned in the previous step, you will need to also set up data for the component's properties in your code, e.g. in app.js (or similarly, in the code of any container component in your project.) To set up the items and settings, use the fields supported by the core component, as detailed in core product's technical reference.

    
    var item1 = { content: 'My summary task' };
    var item2 = { content: 'My standard task', indentation: 1,
                  start: new Date(2012, 8, 2, 8, 0, 0), finish: new Date(2012, 8, 7, 16, 0, 0), 
                  completedFinish: new Date(2012, 8, 5, 16, 0, 0), assignmentsContent: 'My resource' };
    var items = [ item1, item2 ];
    var item3 = { content: 'My milestone', indentation: 1,
                  start: new Date(2012, 8, 7, 16, 0, 0), isMilestone: true };
    items.push(item3);
    …
    var settings = { … };
    var license = "…"; // upon purchasing a product license from DlhSoft
    // Vue setup
    var app = new Vue({
      el: '#app',
      data: {
        items: items,
        settings: settings,
        license: license
      },
      methods: {
        onItemChanged: function(args) {
          var item = args.item, propertyName = args.propertyName, isDirect = args.isDirect, isFinal = args.isFinal;
          console.log(propertyName + ' changed for ' + item.content + '.');
        }
      }
    });
    

    Properties that you may provide values for (applying to all components) are listed below.

    Property Details
    items Actual data to be presented (e.g. task or resource items, depending on the specific component, see technical reference)
    settings Customizations for the appearance and behavior of the component (see technical reference)
    license String value generated by DlhSoft License Manager tool upon purchasing a product license (to remove nag screens)

    Events that you many hook up in your app (applying to all components) are also available:

    Event Details
    change Called upon client side item changes