summaryrefslogtreecommitdiffstats
path: root/include/scsi
AgeCommit message (Expand)Author
2018-05-29block: rename BLK_EH_NOT_HANDLED to BLK_EH_DONEChristoph Hellwig
2018-05-14scsi/osd: remove the gfp argument to osd_start_requestChristoph Hellwig
2018-04-18scsi: core: remove reference to scsi_show_extd_sense()John Pittman
2018-04-05Merge tag 'scsi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/j...Linus Torvalds
2018-04-05Merge tag 'dma-mapping-4.17' of git://git.infradead.org/users/hch/dma-mappingLinus Torvalds
2018-04-03Merge branch 'fixes' into miscJames Bottomley
2018-03-27Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/...Linus Torvalds
2018-03-19scsi: remove the old scsi_module.c initialization modelChristoph Hellwig
2018-03-16scsi: Add NO_DMA dummies for SCSI DMA mapping APIGeert Uytterhoeven
2018-03-14scsi: core: introduce force_blk_mqMing Lei
2018-03-12scsi: core: Make SCSI Status CONDITION MET equivalent to GOODDouglas Gilbert
2018-03-07Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/...Linus Torvalds
2018-03-01scsi: core: Avoid that ATA error handling can trigger a kernel hang or oopsBart Van Assche
2018-02-15scsi: core: host template attribute groupsStanislav Nijnikov
2018-02-03Merge tag 'scsi-postmerge' of git://git.kernel.org/pub/scm/linux/kernel/git/j...Linus Torvalds
2018-01-31Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdmaLinus Torvalds
2018-01-31Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsiLinus Torvalds
2018-01-30Merge tag v4.15 of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...Jason Gunthorpe
2018-01-23IB/srp: Add RDMA/CM supportBart Van Assche
2018-01-22scsi: core: Add VENDOR_SPECIFIC sense code definitionsHannes Reinecke
2018-01-10scsi: libsas: direct call probe and destructJason Yan
2018-01-08scsi: sd: Remove zone write lockingDamien Le Moal
2018-01-08scsi: libsas: Use new workqueue to run sas event and disco eventJason Yan
2018-01-08scsi: libsas: make the event threshold configurableJason Yan
2018-01-08scsi: libsas: shut down the PHY if events reached the thresholdJason Yan
2018-01-08scsi: libsas: Use dynamic alloced work to avoid sas event lostJason Yan
2018-01-03scsi: scsi_transport_fc: fix typos on 64/128 GBit define namesJames Smart
2017-12-07scsi: core: Unexport scsi_initialize_rq()Bart Van Assche
2017-12-07scsi: core: Ensure that the SCSI error handler gets woken upBart Van Assche
2017-11-21scsi: libsas: align sata_device's rps_resp on a cachelineHuacai Chen
2017-11-16scsi: Use 'blist_flags_t' for scsi_devinfo flagsHannes Reinecke
2017-11-14Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsiLinus Torvalds
2017-11-14Merge branch 'for-4.15/block' of git://git.kernel.dk/linux-blockLinus Torvalds
2017-11-13Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/ke...Linus Torvalds
2017-11-10block, scsi: Make SCSI quiesce and resume work reliablyBart Van Assche
2017-11-08scsi: scsi_transport_fc: add 64GBIT and 128GBIT port speed definitionsJames Smart
2017-11-02License cleanup: add SPDX GPL-2.0 license identifier to files with no licenseGreg Kroah-Hartman
2017-11-01scsi: sas: Convert timers to use timer_setup()Kees Cook
2017-10-27scsi: fcoe: Convert timers to use timer_setup()Kees Cook
2017-10-18scsi: scsi_error: Handle power-on reset unit attentionHannes Reinecke
2017-10-17scsi: scsi_devinfo: Reformat blacklist flagsHannes Reinecke
2017-10-16scsi: sd_zbc: Move ZBC declarations to scsi_proto.hDamien Le Moal
2017-10-02scsi: libiscsi: Remove iscsi_destroy_sessionKhazhismel Kumykov
2017-10-02scsi: sd: Implement blacklist option for WRITE SAME w/ UNMAPMartin K. Petersen
2017-09-15scsi: libsas: remove unused port_gone_completion and DISCE_PORT_GONEJason Yan
2017-09-15scsi: libsas: remove the numbering for each event enumJason Yan
2017-09-15scsi: libsas: kill useless ha_event and do some cleanupJason Yan
2017-09-13Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsiLinus Torvalds
2017-09-07Merge branch 'fixes' into miscJames Bottomley
2017-09-05scsi: Remove Scsi_Host.uspace_req_qBart Van Assche
41' href='#n141'>141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
<!--
  - @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
  -
  - @author John Molakvoæ <skjnldsv@protonmail.com>
  - @author Charismatic Claire <charismatic.claire@noservice.noreply>
  -
  - @license GNU AGPL version 3 or any later version
  -
  - This program is free software: you can redistribute it and/or modify
  - it under the terms of the GNU Affero 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 Affero General Public License for more details.
  -
  - You should have received a copy of the GNU Affero General Public License
  - along with this program. If not, see <http://www.gnu.org/licenses/>.
  -
  -->

<template>
	<Content app-name="contacts" :class="{'icon-loading': loading}">
		<!-- new-contact-button + navigation + settings -->
		<AppNavigation>
			<!-- new-contact-button -->
			<AppNavigationNew v-if="!loading"
				button-id="new-contact-button"
				:text="t('contacts','New contact')"
				button-class="icon-add"
				:disabled="!defaultAddressbook"
				@click="newContact" />

			<!-- groups list -->
			<ul v-if="!loading" id="groups-list">
				<AppNavigationItem v-for="item in menu"
					:key="item.key"
					:to="item.router"
					:title="item.text"
					:icon="item.icon">
					<template slot="actions">
						<ActionButton v-for="action in item.utils.actions"
							:key="action.text"
							:icon="action.icon"
							@click="action.action">
							{{ action.text }}
						</ActionButton>
					</template>
					<AppNavigationCounter slot="counter">
						{{ item.utils.counter }}
					</AppNavigationCounter>
				</AppNavigationItem>
			</ul>

			<!-- settings -->
			<AppNavigationSettings v-if="!loading">
				<SettingsSection />
			</AppNavigationSettings>
		</AppNavigation>

		<AppContent>
			<!-- go back to list when in details mode -->
			<div v-if="selectedContact && isMobile"
				id="app-details-toggle"
				class="icon-confirm"
				tabindex="0"
				@click="showList" />

			<div id="app-content-wrapper">
				<!-- contacts list -->
				<ContactsList :list="contactsList"
					:contacts="contacts"
					:loading="loading"
					:search-query="searchQuery" />

				<!-- main contacts details -->
				<ContactDetails :loading="loading" :contact-key="selectedContact" />
			</div>
		</AppContent>
		<Modal v-if="isImporting"
			:clear-view-delay="-1"
			:can-close="isImportDone"
			@close="closeImport">
			<ImportScreen />
		</Modal>
	</Content>
</template>

<script>
import AppContent from '@nextcloud/vue/dist/Components/AppContent'
import AppNavigation from '@nextcloud/vue/dist/Components/AppNavigation'
import AppNavigationItem from '@nextcloud/vue/dist/Components/AppNavigationItem'
import AppNavigationCounter from '@nextcloud/vue/dist/Components/AppNavigationCounter'
import AppNavigationNew from '@nextcloud/vue/dist/Components/AppNavigationNew'
import AppNavigationSettings from '@nextcloud/vue/dist/Components/AppNavigationSettings'
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
import Content from '@nextcloud/vue/dist/Components/Content'
import Modal from '@nextcloud/vue/dist/Components/Modal'
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile'

import moment from 'moment'
import download from 'downloadjs'
import { VCardTime } from 'ical.js'

import SettingsSection from '../components/SettingsSection'
import ContactsList from '../components/ContactsList'
import ContactDetails from '../components/ContactDetails'
import ImportScreen from '../components/ImportScreen'

import Contact from '../models/contact'
import rfcProps from '../models/rfcProps'

import client from '../services/cdav'

const GROUP_ALL_CONTACTS = t('contacts', 'All contacts')
const GROUP_NO_GROUP_CONTACTS = t('contacts', 'Not grouped')

export default {
	name: 'Contacts',

	components: {
		AppContent,
		AppNavigation,
		AppNavigationItem,
		AppNavigationCounter,
		AppNavigationNew,
		AppNavigationSettings,
		ActionButton,
		ContactDetails,
		ContactsList,
		Content,
		ImportScreen,
		Modal,
		SettingsSection,
	},

	mixins: [
		isMobile,
	],

	// passed by the router
	props: {
		selectedGroup: {
			type: String,
			default: undefined,
			required: true,
		},
		selectedContact: {
			type: String,
			default: undefined,
		},
	},

	data() {
		return {
			loading: true,
			searchQuery: '',
		}
	},

	computed: {
		// store getters
		addressbooks() {
			return this.$store.getters.getAddressbooks
		},
		sortedContacts() {
			return this.$store.getters.getSortedContacts
		},
		contacts() {
			return this.$store.getters.getContacts
		},
		groups() {
			return this.$store.getters.getGroups
		},
		orderKey() {
			return this.$store.getters.getOrderKey
		},
		importState() {
			return this.$store.getters.getImportState
		},

		// importing states
		isImporting() {
			return this.importState.stage !== 'default'
		},
		isImportDone() {
			return this.importState.stage === 'done'
		},

		// first enabled addressbook of the list
		defaultAddressbook() {
			return this.addressbooks.find(addressbook => !addressbook.readOnly && addressbook.enabled)
		},

		/**
		 * Contacts list based on the selected group.
		 * Those filters are pretty fast, so let's only
		 * intersect the groups contacts and the full
		 * sorted contacts List.
		 *
		 * @returns {Array}
		 */
		contactsList() {
			if (this.selectedGroup === GROUP_ALL_CONTACTS) {
				return this.sortedContacts
			} else if (this.selectedGroup === GROUP_NO_GROUP_CONTACTS) {
				return this.ungroupedContacts.map(contact => this.sortedContacts.find(item => item.key === contact.key))
			}
			const group = this.groups.filter(group => group.name === this.selectedGroup)[0]
			if (group) {
				return this.sortedContacts.filter(contact => group.contacts.indexOf(contact.key) >= 0)
			}
			return []
		},

		ungroupedContacts() {
			return this.sortedContacts.filter(contact => this.contacts[contact.key].groups && this.contacts[contact.key].groups.length === 0)
		},

		// generate groups menu from groups store
		groupsMenu() {
			return this.groups.map(group => {
				return {
					id: group.name.replace(' ', '_'),
					key: group.name.replace(' ', '_'),
					router: {
						name: 'group',
						params: { selectedGroup: group.name },
					},
					text: group.name,
					utils: {
						counter: group.contacts.length,
						actions: [
							{
								icon: 'icon-download',
								text: 'Download',
								action: () => this.downloadGroup(group),
							},
						],
					},
				}
			}).sort(function(a, b) {
				return parseInt(b.utils.counter) - parseInt(a.utils.counter)
			})
		},

		// building the main menu
		menu() {
			return this.groupAllGroup.concat(this.groupNotGrouped.concat(this.groupsMenu))
		},

		// default group for every contacts
		groupAllGroup() {
			return [{
				id: 'everyone',
				key: 'everyone',
				icon: 'icon-contacts-dark',
				router: {
					name: 'group',
					params: { selectedGroup: GROUP_ALL_CONTACTS },
				},
				text: GROUP_ALL_CONTACTS,
				utils: {
					counter: this.sortedContacts.length,
				},
			}]
		},

		// default group for every contacts
		groupNotGrouped() {
			if (this.ungroupedContacts.length === 0) {
				return []
			}
			return [{
				id: 'notgrouped',
				key: 'notgrouped',
				icon: 'icon-user',
				router: {
					name: 'group',
					params: { selectedGroup: GROUP_NO_GROUP_CONTACTS },
				},
				text: GROUP_NO_GROUP_CONTACTS,
				utils: {
					counter: this.ungroupedContacts.length,
				},
			}]
		},
	},

	watch: {
		// watch url change and group select
		selectedGroup() {
			if (!this.isMobile) {
				this.selectFirstContactIfNone()
			}
		},
		// watch url change and contact select
		selectedContact() {
			if (!this.isMobile) {
				this.selectFirstContactIfNone()
			}
		},
	},

	mounted() {
		/**
		 * Register search
		 */
		this.search = new OCA.Search(this.search, this.resetSearch)
	},

	beforeMount() {
		// get addressbooks then get contacts
		client.connect({ enableCardDAV: true }).then(() => {
			console.debug('Connected to dav!', client)
			this.$store.dispatch('getAddressbooks')
				.then((addressbooks) => {

					// No addressbooks? Create a new one!
					if (addressbooks.length === 0) {
						this.$store.dispatch('appendAddressbook', { displayName: t('contacts', 'Contacts') })
							.then(() => {
								this.fetchContacts()
							})
					// else, let's get those contacts!
					} else {
						this.fetchContacts()
					}
				})
				// check local storage for orderKey
			if (localStorage.getItem('orderKey')) {
				// run setOrder mutation with local storage key
				this.$store.commit('setOrder', localStorage.getItem('orderKey'))
			}
		})
	},

	methods: {
		async newContact() {
			const rev = new VCardTime()
			const contact = new Contact(`
				BEGIN:VCARD
				VERSION:4.0
				PRODID:-//Nextcloud Contacts v${appVersion}
				END:VCARD
			`.trim().replace(/\t/gm, ''),
			this.defaultAddressbook)

			contact.fullName = t('contacts', 'New contact')
			rev.fromUnixTime(Date.now() / 1000)
			contact.rev = rev

			// itterate over all properties (filter is not usable on objects and we need the key of the property)
			const properties = rfcProps.properties
			for (const name in properties) {
				if (properties[name].default) {
					const defaultData = properties[name].defaultValue
					// add default field
					const property = contact.vCard.addPropertyWithValue(name, defaultData.value)
					// add default type
					if (defaultData.type) {
						property.setParameter('type', defaultData.type)

					}
				}
			}

			// set group if it's selected already
			// BUT NOT if it's the _fake_ groups like all contacts and not grouped
			if ([GROUP_ALL_CONTACTS, GROUP_NO_GROUP_CONTACTS].indexOf(this.selectedGroup) === -1) {
				contact.groups = [this.selectedGroup]
			}
			try {
				// this will trigger the proper commits to groups, contacts and addressbook
				await this.$store.dispatch('addContact', contact)
				await this.$router.push({
					name: 'contact',
					params: {
						selectedGroup: this.selectedGroup,
						selectedContact: contact.key,
					},
				})
			} catch (error) {
				OC.Notification.showTemporary(t('contacts', 'Unable to create the contact.'))
				console.error(error)
			}
		},

		/**
		 * Dispatch sorting update request to the store
		 *
		 * @param {string} orderKey the object key to order by
		 */
		updateSorting(orderKey = 'displayName') {
			this.$store.commit('setOrder', orderKey)
			this.$store.commit('sortContacts')
		},

		/**
		 * Fetch the contacts of each addressbooks
		 */
		fetchContacts() {
			// wait for all addressbooks to have fetch their contacts
			Promise.all(this.addressbooks.map(addressbook => {
				if (addressbook.enabled) {
					return this.$store.dispatch('getContactsFromAddressBook', { addressbook })
				}
			})).then(results => {
				this.loading = false
				if (!this.isMobile) {
					this.selectFirstContactIfNone()
				}
			})
		},

		/**
		 * Select the first contact of the list
		 * if none are selected already
		 */
		selectFirstContactIfNone() {
			const inList = this.contactsList.findIndex(contact => contact.key === this.selectedContact) > -1
			if (this.selectedContact === undefined || !inList) {
				if (this.selectedContact && !inList) {
					OC.Notification.showTemporary(t('contacts', 'Contact not found'))
				}
				if (Object.keys(this.contactsList).length) {
					this.$router.push({
						name: 'contact',
						params: {
							selectedGroup: this.selectedGroup,
							selectedContact: Object.values(this.contactsList)[0].key,
						},
					})
				}
			}
		},

		/**
		 * Download vcard promise as vcard file
		 *
		 * @param {Promise} vcardPromise the full vcf file promise
		 */
		async downloadVcardPromise(vcardPromise) {
			vcardPromise.then(response => {
				const filename = moment().format('YYYY-MM-DD_HH-mm') + '_' + response.groupName + '.vcf'
				download(response.data, filename, 'text/vcard')
			})
		},

		/**
		 * Download group of contacts
		 *
		 * @param {Object} group of contacts to be downloaded
		 */
		downloadGroup(group) {
			// get grouped contacts
			let groupedContacts = {}
			group.contacts.map((key) => {
				const id = this.contacts[key].addressbook.id
				groupedContacts = Object.assign({
					[id]: {
						addressbook: this.contacts[key].addressbook,
						contacts: [],
					},
				}, groupedContacts)
				groupedContacts[id].contacts.push(this.contacts[key].url)
			})
			// create vcard promise with the requested contacts
			const vcardPromise = Promise.all(
				Object.keys(groupedContacts).map(key =>
					groupedContacts[key].addressbook.dav.addressbookMultigetExport(groupedContacts[key].contacts)))
				.then(response => ({
					groupName: group.name,
					data: response.map(data => data.body).join(''),
				}))
			// download vcard
			this.downloadVcardPromise(vcardPromise)
		},

		/* SEARCH */
		search(query) {
			this.searchQuery = query
		},
		resetSearch() {
			this.searchQuery = ''
		},

		/**
		 * Show the list and deselect contact
		 */
		showList() {
			// Reset the selected contact
			this.$router.push({
				name: 'contact',
				params: {
					selectedGroup: this.selectedGroup,
					selectedContact: undefined,
				},
			})
		},

		/**
		 * Done importing, the user closed the import status screen
		 */
		closeImport() {
			// TODO: remove after https://github.com/nextcloud/nextcloud-vue/pull/323
			if (this.isImportDone) {
				this.$store.dispatch('changeStage', 'default')
			}
		},
	},
}
</script>