index.php 2.02 KB
<?php
    
    /**
     * @var                       $this yii\web\View
     * @var \common\models\Call[] $calls
     */
    
    $this->title = 'My Yii Application';
?>
<div class="site-index">
  
  <div class="jumbotron">
  
  </div>
  
  <div class="body-content">
    
    <div id="app">
      <div class="row">
        <table class="bordered">
          <thead>
            <tr>
              <th>ID</th>
              <th>Company</th>
              <th>Status</th>
              <th>Duration</th>
            </tr>
          </thead>
          <tbody>
            <tr v-if="" v-for="call in calls">
              <td>{{call.id}}</td>
              <td>{{call.company}}</td>
              <td>{{call.status}}</td>
              <td>{{call.duration}}</td>
            </tr>
          </tbody>
        </table>
        <div class="row">
          <div class="col s5 input-field">
            <label for="search-company">Company</label>
            <input v-model="search" id="search-company" type="text">
            <button v-on:click="fetchSearch()" class="waves-effect waves-light btn">Search</button>
          </div>
          
        </div>
      </div>
      
    </div>
  </div>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            calls: null,
            search: null
        },
        created: function() {
            this.fetchData()
        },
        methods: {
            fetchData: function() {
                var self = this;
                axios.get('/rest/calls')
                     .then(function(response) {
                         console.log(response.data);
                         self.calls = response.data;
                     });
            },
            fetchSearch: function() {
                var self = this;
                axios.get('/rest/calls/search?word=' + self.search)
                     .then(function(response) {
                         console.log(response.data);
                         self.calls = response.data;
                     });
            }
        }
    })
</script>