activity.html 8.58 KB
Newer Older
Giorgos Korfiatis's avatar
Giorgos Korfiatis committed
1
<!--
Giorgos Korfiatis's avatar
Giorgos Korfiatis committed
2
Copyright (C) 2015-2016 GRNET S.A.
Giorgos Korfiatis's avatar
Giorgos Korfiatis committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
17
<script type="text/javascript">
18

19 20 21 22
    function check_gpg() {
        exec("which gpg", function(error, stdout, stderr) {
            if(error) {
                $("#gpg-alert").show();
Efthymia Bika's avatar
Efthymia Bika committed
23
            } else {
24
                $("#gpg-alert").hide();
Efthymia Bika's avatar
Efthymia Bika committed
25
            }
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
        });
    }
    if(process.platform != "win32") {
        check_gpg();
    }

    if(typeof clouds === 'undefined') {
        load_data_from_file(CLOUDS_CONF_FILE, show_cloud_msg);
    } else {
        show_cloud_msg(clouds);
    }

    function show_cloud_msg(data) {
        if(typeof clouds === 'undefined') {
            if(data != "") {
                clouds = JSON.parse(data);
            } else {
                clouds = new Object();
Efthymia Bika's avatar
Efthymia Bika committed
44
            }
45 46 47
        }
        if(Object.keys(clouds).length == 0) {
            $("#cloud-alert").show();
Efthymia Bika's avatar
Efthymia Bika committed
48 49
        } else {
            update_clouds_settings(clouds);
50 51 52
        }
    }

Efthymia Bika's avatar
Efthymia Bika committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    function update_clouds_settings(clouds) {
        function handle_error(data) {
            console.error("Error updating clouds settings " + data);
        }
        function handle_result() {
            var cloud = arguments[0].cloud;
            var data = arguments[1];
            var endpoints = JSON.parse(data).access.serviceCatalog
            $.each(endpoints, function(i, endpoint) {
                switch(endpoint.type) {
                    case 'account':
                        try {
                            clouds[cloud.name].astakos_account =
                                endpoint['endpoints'][0]['publicURL'];
                            write_conf_file(CLOUDS_CONF_FILE, clouds);
                        } catch(err) {
                            console.log('Failed to get astakos_account '
                                + err);
                        }
                    break;
                }
            });
        }
        $.each(clouds, function(i, cloud) {
            if(typeof cloud.astakos_account == 'undefined') {
                var astakos = getClient(
                        'astakos_notoken', cloud.auth_url, null, cloud.cert);
                astakos.post('/tokens', null, null, 200,
                    handle_result.bind(null, {cloud: cloud}), handle_error);
            }
        });
    }


87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    load_data_from_file(BACKUP_CONF_FILE, render_backup_sets);

    function go_to_backup(backup) {
        selected_backup = backup;
        $("#backup-tab-link").trigger("click");
    }

    function show_delete_modal(backup) {
        $("#del-modal-p").html("<p>Are you sure you want to delete "
            + backup.cloud + "/" +  backup.name + '?</p>' +
            "<p>NOTE: To actually remove backup sets from remote" +
            " container you have to manually purge it.</p>");
        $("#delete-modal").foundation("reveal", "open");
        var i = 0;
        $("#delete-modal").on('close.fndtn.reveal', function(e) {
            if(e.namespace !== "fndtn.reveal") return;
            i++;
            $(this).click(function(event) {
                // event is fired more than once so have to check
                if(event.target.id == "del-modal-accept" && i == 1) {
                    delete_backup(backup);
                }
            });
        });
    }

    function render_backup_sets(data) {
        $("#backup_list").remove();
        // backups is undefined the first time, when
        // reading data from file
        if(typeof backups === 'undefined') {
            if(data != "") {
                backups = JSON.parse(data);
            } else {
                backups = new Object();
Efthymia Bika's avatar
Efthymia Bika committed
122
            }
123 124 125 126 127 128 129 130
        }
        if(Object.keys(backups).length == 0) {
            $("#backup-alert").show();
        }
        var ul = $("<ul></ul>")
            .attr("class", "small-block-grid-4")
            .attr("id", "backup_list");
        $.each(backups, function(i, backup) {
Efthymia Bika's avatar
Efthymia Bika committed
131 132
            var li = $("<div></div>")
                .attr("class", "backup-box")
133 134 135 136
                .attr("id", "box_" + backup.name);
            var a = $("<a>" + backup.cloud + "/" + backup.name + "</a>")
                .attr("href", "#")
                .attr("id", "box_a_" + backup.name)
Efthymia Bika's avatar
Efthymia Bika committed
137
                .attr("class", "left go-to-backup")
138 139 140 141 142 143 144 145 146
                .attr("onclick", "go_to_backup('" +
                    backup.cloud + "/" + backup.name + "')");
            li.append(a);

            var a_del = $("<a><i class='fa fa-trash-o delete_icon'></i></a>")
                .attr("href", "#")
                .attr("class", "right")
                .click(function() {
                    show_delete_modal(backup);
147
                });
148 149
            li.append(a_del);

Efthymia Bika's avatar
Efthymia Bika committed
150
            li.append("<hr>");
151 152 153 154 155 156 157 158 159 160 161 162
            var local_dir = $("<span>" + backup.local_dir + "</span>");
            li.append(local_dir);

            if(typeof backup.first_backup != 'undefined') {
                li.append("<br>");
                var first = new Date(backup.first_backup).toLocaleString();
                var first_p = $("<span>First : " + first + " </span>");
                li.append(first_p);
                li.append("<br>");
                var last = new Date(backup.last_backup).toLocaleString();
                var last_p = $("<span>Last : " + last + " </span>");
                li.append(last_p);
163
            }
164 165 166
            if(typeof backup.last_status != 'undefined') {
                li.append("<br>");
                li.append("<br>");
Efthymia Bika's avatar
Efthymia Bika committed
167 168 169 170 171
                var status_class = (backup.last_status == "Failed") ?
                    "fail-span" : "succeed-span";
                var status_p = $("<span>Status : <i class='" + status_class
                        + "'> " + backup.last_status +
                        "</i>&nbsp;&nbsp;</span>");
172 173 174 175 176 177
                li.append(status_p);
                var loader = $("<i></i>")
                    .attr("class", "fa fa-spinner fa-pulse");
                li.append(loader);
                if(backup.last_status != "Running") {
                    loader.hide();
Efthymia Bika's avatar
Efthymia Bika committed
178
                }
Efthymia Bika's avatar
Efthymia Bika committed
179
            }
Efthymia Bika's avatar
Efthymia Bika committed
180 181 182
            var extLi = $("<li></li>");
            extLi.append(li);
            ul.append(extLi);
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
            $("#backup-table").append(ul);
        });

    }
    window.setInterval(function() {
        render_backup_sets("");
    }, 3000);

</script>

<div class="row">
    <div class="small-12 columns panel alert hide" id="gpg-alert">
        <span>
            <i class="fa fa-exclamation-circle"></i>
            BaaS uses <a href="#"
                onclick="gui.Shell.openExternal('https://www.gnupg.org/download/index.html');">
                GnuPG</a>
            in order to encrypt your backups, though
            no gpg installation was found on your system.
            You must install gpg separately.
        </span>
    </div>
</div>
<div class="row">
    <div class="small-12 columns panel hide" id="cloud-alert">
        <span>
            <i class="fa fa-exclamation-circle"></i>
            No cloud settings found. To start you must set a
            <a onclick="$('#cloud-settings-link').trigger('click');">
            cloud configuration.</a>
        </span>
    </div>
</div>
<div class="row">
    <div class="small-12 columns panel hide" id="backup-alert">
        <span>
            <i class="fa fa-exclamation-circle"></i>
            No backup sets found.
            <a onclick="$('#backup-tab-link').trigger('click');">
            Create a new one.</a>
        </span>
    </div>
</div>
<div class="row">
    <div class="small-12 columns" id="backup-table">
    </div>
</div>
<div id="delete-modal" class="reveal-modal medium"
    data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
    <p id="del-modal-p"></p>
    <a id="del-modal-cancel" class="button radius small"
        onclick="$('#delete-modal').foundation('reveal', 'close');">
        Cancel
    </a>
    <a id="del-modal-accept" class="button radius small alert right"
        onclick="$('#delete-modal').foundation('reveal', 'close');">
        Delete
    </a>
    <a class="close-reveal-modal" aria-label="Close">&#215;</a>
</div>

<script type="text/javascript">
    $(document).foundation();
</script>