src_js/iconolab-bundle/src/components/editor/AnnotationList.vue
author Alexandre Segura <mex.zktk@gmail.com>
Mon, 13 Mar 2017 18:48:35 +0100
changeset 418 a04c55054afe
child 433 616fc1fad25f
permissions -rw-r--r--
Introduce display of all annotations at the same time. - Add stats to serialized annotation. - Introduce AnnotationList component. - Pass array of annotations to component. - Handle click on annotation & drawing.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
418
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     1
<template>
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     2
    <div class="list-group">
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     3
        <a v-for="annotation in annotations"
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     4
            ref="annotations"
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     5
            @click="onAnnotationClick($event, annotation)"
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     6
            :href="'#' + annotation.annotation_guid"
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     7
            class="list-group-item"
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     8
            v-bind:class="{ active: isActive(annotation) }">
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     9
            <h3 class="small list-group-item-heading">
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    10
                {{ annotation.title }}
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    11
                <button type="button" class="close" data-dismiss="alert" aria-label="Close" @click="onAnnotationClose">
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    12
                    <span aria-hidden="true">&times;</span>
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    13
                </button>
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    14
            </h3>
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    15
            <p class="list-group-item-text" v-for="tag in annotation.tags">{{ tag.tag_label }}</p>
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    16
            <div class="list-group-item-footer">
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    17
              <i class="fa fa-comment"></i> {{ getCommentsCount(annotation) }}
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    18
            </div>
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    19
        </a>
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    20
    </div>
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    21
</template>
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    22
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    23
<script>
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    24
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    25
    import _ from 'lodash';
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    26
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    27
    export default {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    28
        props: [
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    29
            'annotations',
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    30
            'annotation'
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    31
        ],
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    32
        mounted() {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    33
            if (this.annotation) {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    34
                this.slideToAnnotation();
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    35
            }
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    36
        },
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    37
        watch: {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    38
            annotation: function(annotation) {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    39
                if (annotation) {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    40
                    this.slideToAnnotation();
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    41
                }
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    42
            }
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    43
        },
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    44
        methods: {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    45
            onAnnotationClick: function(e, annotation) {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    46
                e.preventDefault();
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    47
                this.$emit('click:annotation', annotation);
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    48
            },
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    49
            onAnnotationClose: function(e) {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    50
                e.preventDefault();
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    51
                e.stopPropagation();
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    52
                this.$emit('close:annotation');
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    53
            },
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    54
            isActive: function(annotation) {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    55
                return annotation === this.annotation;
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    56
            },
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    57
            getCommentsCount: function(annotation) {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    58
                var commentsCount = annotation.stats.comments_count;
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    59
                return commentsCount + ' commentaire' + (commentsCount > 1 ? 's' : '');
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    60
            },
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    61
            slideToAnnotation: function() {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    62
                var el = _.find(this.$refs.annotations, (el) => {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    63
                    return $(el).attr('href') === ('#' + this.annotation.annotation_guid);
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    64
                });
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    65
                if (el) {
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    66
                    var $container = $(this.$el.closest('.panel'));
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    67
                    $container.animate({
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    68
                        scrollTop: $container.scrollTop() - $container.offset().top + $(el).offset().top
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    69
                    }, 600);
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    70
                }
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    71
            }
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    72
        }
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    73
    }
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    74
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    75
</script>
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    76
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    77
<style scoped>
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    78
a04c55054afe Introduce display of all annotations at the same time.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    79
</style>